Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

In C#, what is the difference between public, private, protected, and having no access modifier?

All my college years I have been using public, and would like to know the difference between public, private, and protected?

Also what does static do as opposed to having nothing?
by

2 Answers

rahul07
Public - If you can see the class, then you can see the method

Private - If you are part of the class, then you can see the method, otherwise not.

Protected - Same as Private, plus all descendants can also see the method.

Static (class) - Remember the distinction between "Class" and "Object" ? Forget all that. They are the same with "static"... the class is the one-and-only instance of itself.

Static (method) - Whenever you use this method, it will have a frame of reference independent of the actual instance of the class it is part of.
pankajshivnani123
public - can be access by anyone anywhere.
private - can only be accessed from with in the class it is a part of.
protected - can only be accessed from with in the class or any object that inherits off of the class.

Nothing is like null but in VB.
Static means you have one instance of that object, method for every instance of that class.

Login / Signup to Answer the Question.