tabs ↹ over ␣ ␣ ␣ spaces

by Jiří {x2} Činčura

Struct with “main method” as an entry point

7 Nov 2019 1 mins .NET, .NET Core, C#

Have you ever thought about the most basic structure of an application? The main method and its placement in Program class

Today as I was creating yet another console app to test something (boxing of structs, in case you’d like to ask) I looked at the class Program piece and tried to rewrite it to struct. Just to try it. Would it work? Given the main does not even have to be public and it’s static, which works for struct, it probably should, right?

struct Program
{
	static void Main(string[] args)
	{
		Console.WriteLine("Hello struct!");
	}
}

Trying to compile this simple piece of code works like a charm. Are you asking what this might be useful for? I don’t have an answer. I think it does not have any real useful application. But this made me look up “specification” of what main method should look like, at least.

Profile Picture Jiří Činčura is .NET, C# and Firebird expert. He focuses on data and business layers, language constructs, parallelism, databases and performance. For almost two decades he contributes to open-source, i.e. FirebirdClient. He works as a senior software engineer for Microsoft. Frequent speaker and blogger at www.tabsoverspaces.com.