[Solved] different ways of declaring main function c# [closed]


I think the better question is, What does each part of the typical Main method declaration mean?

Can you take out some keywords? Sure, but the method will not necessarily be the same as the one defined below.

public static void Main(string[] args)

public refers to the visibility, without public, the code will use its default visibility

static means that this is a class method. Without static, the method becomes an instance method.

void simply means that the return type is void. Can you change it to int? Sure, but you better return an int at the end.

Main is just the name. Names can obviously be switched but then you wouldn’t call it the “main method” anymore

string[] args is just a parameter of arguments. Could you remove it? Yes, but then you could not use any arguments in the method.

In General: You can interchange things, but do not expect the exact same behavior out of the method. Understanding what each keyword does etc is the key here.

solved different ways of declaring main function c# [closed]