top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Difference between public static void Main() and private static void Main() in C#?

+1 vote
1,071 views

What is the difference between

public static void Main()

and

private static void Main()

in C#?

posted Feb 19, 2014 by Khusboo

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

2 Answers

+1 vote
 
Best answer

The difference between both is the only difference in public and private access modifiers because both are valid.It totally depends on the usage of application which one to use.
If you want to initiate entry point by any external program, (i.e. use as API, for testing purpose) then you might need to make it public so it is accessible.
If you know there is no external usage for the application then it is better to make it private so no external application get access to it.

answer Nov 17, 2014 by Manikandan J
+1 vote

There is difference, because first one is public and second one is private, so when you'd try to use the first one from outside the class it would work just fine, but wouldn't work with the second one.

However, there is no difference if you're trying to make one of these an entry point in you application. Entry point method can be either public or private, it doesn't matter.

answer Feb 23, 2014 by Neeraj Pandey
Similar Questions
+2 votes

Hai,friends if you are know the difference means tell me

+3 votes

By-default all the methods & variables in class are private.

In C#.net Main() method is private then how compiler access this Main() Method out side the class because compiler is not part of our program then how compiler access this Main() method?

Here we loose our data abstraction property ? Can anyone put some light on it?

+2 votes

Many a times in C we get these two type of main function one had void as parameter one has none. Now the question is what is the difference between these two?

...