docs
docs copied to clipboard
How to declare static variable above main method in Top Level statement
Type of issue
Code doesn't work
Description
As We use top Level Statement don't require to write main method as, I have a static and non static variable I want to write the static and non static variable above the main method and check how static variable works but this case top level statement failed how i write that.
`using System; class HelloWorld { static int x=100; int y; static void Main() { int z=-9; HelloWorld h=new HelloWorld(); Console.WriteLine(x); Console.WriteLine(h.y); Console.WriteLine(z);
} }`
Page URL
https://learn.microsoft.com/en-us/dotnet/core/tutorials/top-level-templates
Content source URL
https://github.com/dotnet/docs/blob/main/docs/core/tutorials/top-level-templates.md
Document Version Independent Id
926db74c-be79-f7cd-a4e9-e156dafa6287
Article author
@tdykstra
Metadata
- ID: 447e23ae-0256-d8c1-4dca-d31fe21602a5
- Service: dotnet-fundamentals