Is there any other way of writing this line of code ?

Khan39

Member
Joined
Nov 25, 2019
Messages
9
Programming Experience
Beginner
I am new to C# ,

Is there any other way of writing this line of code ?
static void Main(string[] args)

?

I have seen shorter versions of this somewhere but don't remember where exactly

Please help

Thanks
 
Why would you think that a shorter version of that short line of code would be a good idea in the first place? You must be asking this rather odd question for a reason. Plenty of people ask how to optimise code but it's usually more than a single method declaration.
 
@jmcilhinney

I am Pscman39 from vb.net forum, i wanted to start learning VB.net but i decided to learn C# instead


static void Main(string[] args)
The next line defines the Main method, which is the entry point for all C# programs. The Main method states what the class does when executed

So are there many methods of declaring this Main ?
 
No, there aren't. If you're coming from VB then you may be confused because VB projects have the Application Framework enabled by default, which hides certain complexity from you. Part of what it hides is the Main method. The method exists but it is in auto-generated code that you can't access. If you disable the Application Framework then you can provide your own Main method and it works just like in C#.

There's no reason for you to change the declaration of the Main method in C# and there may well not even be a reason to change the definition. If you're creating a Console app then you will need to put your code into that method or at least call a method that does contain your code. If it's Windows Forms app, you probably don't need to do anything to it. The auto-generated method will contain code that creates and displays your startup form, which is generally all you need there.
 
Back
Top Bottom