C# - Why console window disappear immediately without display my output in C Sharp?

Scenario: Download Scripts

You are working as C# developer and writing Console Application. You would like to display some statics string values and also variables values but console window disappear immediately without you can take a look.

As the values are displayed, so programs completes without waiting for you. One solution for this is to use Console.ReadLine() so it will wait from you to provide input. Once you are done seeing the value, you can simply hit Enter to close the window.

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

namespace _04_Console_Screen_Disappear_Immediately
    class Program
        static void Main(string[] args)
            string testvariable = "This is string variable";
            //Display string
            Console.WriteLine("Welcome to TechBrothersIT.com");
            //display variable variable
            //wait for input

I executed above script and it displayed the values and waited for me to hit Enter to close the console window as we have used the Console.ReadLine().
Console window closing immediately without displaying my output - C#

No comments:

Post a Comment