最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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
    }
  }
}

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
    }
  }
}
Share Improve this question edited Feb 8 at 9:46 DanneManne asked Feb 8 at 9:41 DanneManneDanneManne 376 bronze badges 3
  • 4 Is this not just a Top-level statement? If you're unaware, newer C# versions essentially allow you to remove the boilerplate from the entry to your applications, so the class, Main method and namespace all just disappear from the file. learn.microsoft.com/en-us/dotnet/csharp/fundamentals/… – MoonMist Commented Feb 8 at 9:49
  • 1 The dotnet system provides this internally as an object module that is linked in to your code at build time. If you still want to have it in your source then you can use the --use-program-main option when you generate your project. – OldBoy Commented Feb 8 at 9:52
  • ... do you want to see a disassembly? or is that too low level? – starball Commented 1 hour ago
Add a comment  | 

2 Answers 2

Reset to default 1

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.

Or right click on the code, and choose Refactor, followed by "Convert to 'Program.Main' style program:

发布评论

评论列表(0)

  1. 暂无评论