-1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {



            string genre = "Horror";
            switch (genre)
            {
                case "Drama":
                    Console.WriteLine("Citizen Kane");
                    break;

                case "Comedy":
                    Console.WriteLine("Duck Soup");
                    break;

                case "Adventure":
                    Console.WriteLine("King Kong");
                    break;

                case "Horror":
                    Console.WriteLine("Psycho");
                    break;

                case "Science Fiction":
                    Console.WriteLine("2001: A Space Odyssey");
                    break;
                default:
                    Console.WriteLine("Movie not found");
                    break;

            }
        }
    }
}

It doesnt work on CodeCademy either on VS(the black windows opens for 1sec then gets closed) Somebody knows how to fix that problem? I tried to change the genre horror into Console.ReadLine(); but this also didnt work

Luffy
  • 11
  • 1
    Does this answer your question? [How to keep console window open](https://stackoverflow.com/questions/16952846/how-to-keep-console-window-open) – Charlieface Jan 18 '21 at 14:43
  • Works on try.dot.net. Is it just that you're not waiting before exiting to see the output? What if you run it from a terminal window? – Martin Costello Jan 18 '21 at 14:44
  • Indeed, [everything works fine (fiddle snippet)](https://dotnetfiddle.net/KfeMYs), just add at the end: `Console.ReadKey();` to wait for the user to press a key otherwise the console is immediately closed. –  Jan 18 '21 at 14:47
  • just add console.Readline() at the end of the main method before it exists and you would see the console not going away till you press any key – Nikunj Kakadiya Jan 18 '21 at 14:59

1 Answers1

0

Try this - adding in Console.ReadLine():

    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace ConsoleApp1
    {
        class Program
        {
            static void Main(string[] args)
            {
    
    
    
                string genre = "Horror";
                switch (genre)
                {
                    case "Drama":
                        Console.WriteLine("Citizen Kane");
                        break;
    
                    case "Comedy":
                        Console.WriteLine("Duck Soup");
                        break;
    
                    case "Adventure":
                        Console.WriteLine("King Kong");
                        break;
    
                    case "Horror":
                        Console.WriteLine("Psycho");
                        break;
    
                    case "Science Fiction":
                        Console.WriteLine("2001: A Space Odyssey");
                        break;
                    default:
                        Console.WriteLine("Movie not found");
                        break;
    
                }
                Console.ReadLine();
            }
        }
    }
User7007
  • 331
  • 3
  • 14