Click here to Skip to main content
15,886,060 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hello,
As we know that all c# program start with a Fuction
C#
class program
{ 
public Static void Main()
{
 {
   //
 }
}

then what is the need of public Static void Main()

is program is runnable without this function if yes then why
Posted
Updated 25-Apr-13 21:44pm
v3

All programs need to start somewhere: the static Main method is the place that it all begins - it has to be somewhere that is accessible at the start of the program - so it can't be a class constructor (because there is nothing to construct the first instance of the first class) so it has to be a static method. It is called Main simply so that the linker and so forth all know exactly what to look for!

If it wasn't called Main, it would need a name of some kind - so the designers of teh .NET framework picked a name and stuck with it. It harks back to "C" days, where it was called "main" instead.
 
Share this answer
 
Comments
srishti_ 26-Apr-13 4:14am    
is program is runnable without this function if yes then why
Orcun Iyigun 26-Apr-13 4:22am    
If you think CRITICALLY and read CAREFULLY this will answer your question. <blockquote class="FQ"><div class="FQA">Quote:</div>- it has to be somewhere that is accessible at the start of the program -</blockquote>. So if it is not accessible at the start how do you think it will initialize?
OriginalGriff 26-Apr-13 5:16am    
an application isn't runnable with a Main statement, but an assembly can be executable without one: That is the practical difference between an app and a class library. The first has Main and is runnable, the second doesn't, and isn't. In all other respects they could be identical.
 
Share this answer
 
v2
You need an entry point for a program so the runtime knows where to start executing it.
Please also refer to this question and all the solution: Why main() function should be static in c#?[^].

Regards,
— Manfred
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900