Search code examples
c#visual-studio-codec#-devkit

How to show the hidden default code in Visual Studio Code when using C#?


I use Visual Studio Code and code in C#. I'm using the extension: C# Dev Kit.

But the default code that should always be visible is not shown, how do I get it to show? Do this feature have a name that hide this "default code" ?

The missing code?

using System;

namespace GettingInput
{
  class Program
  {
    static void Main()
    {
      // Code
    }
  }
}

Solution

  • The feature is called "top-level statements" as @MoonMist suggested in the comments. Read more about it here. There's no missing code; the compiler is simply providing it for you (note the comment in the docs that the method is not called main and is not accessible).

    If you want to use the older main method, just paste your existing top-level statement into the code you've written above. No project changes are required; it will simply be detected and used instead.

    Note though that top-level statements can do all the things that a main method could, like access args or return exit codes.