-1

What is default access modifier for Class and for Variable in C#?

For Class, there are two type of Access modifier: Pulic/ Internal. And Internal by Default? For Variable, there are four type of Access modifier: Public/Internal/Protected/Private. And Private by Default?

In Java, Public is the Default Access modifier. But I really do not know what is exactly in C#?

vyclarks
  • 854
  • 2
  • 15
  • 39

2 Answers2

3

It's funny what you can find by using google. For example the MSDN page about classes. It states:

Classes are internal by default.

And later:

Types declared inside a class without an access modifier default to private

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • Can we use Public for variable inside a class? – vyclarks Oct 16 '14 at 05:49
  • 1
    @VyClarks It's syntactically possible. It's bad style though. It breaks encapsulation. If you need something to be public, make it a property or method. – nvoigt Oct 16 '14 at 06:54
1

The default is internal for class and private for class members, but I recommend declaring it explicitly

TGH
  • 38,769
  • 12
  • 102
  • 135