Hide console Window in C#

To hide console window in a C# console application your Program.cs file should be similar to this:

namespace mynamespace
    class Program
        static extern IntPtr GetConsoleWindow();
        static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
        const int SW_HIDE = 0;
        const int SW_SHOW = 5;
        static void Main(string[] args)
            var handle = GetConsoleWindow();
            // Hide
            ShowWindow(handle, SW_HIDE);