1

Inside a class by default everything is private. By default non nested class ,interface, struct, delegate & enum have internal accessibility. But that means if all these comes inside class, everything will become private by default. Are there any types that will become non private inside a class by default?

PS. just a kind of exceptional case like an instance variable that we can't assign any values inside a struct, but by using null coalescing operator we can assign.

Noctis
  • 11,507
  • 3
  • 43
  • 82
peter
  • 8,158
  • 21
  • 66
  • 119
  • @Jon i had look on all those blogs and sites,thats why i am asking is there any exceptional case.If we check any sites you can see instance types we cant initialize inside struct. But we can do it with the help of null coleasing operator – peter Nov 04 '13 at 12:25
  • 1
    In addition, why would you leave their default value? always be explicit and give them the proper accessibility. – Noctis Nov 04 '13 at 12:25
  • 1
    @James That's only true for namespace level declarations. Nested declarations are private by default. – David Arno Nov 04 '13 at 12:30
  • 1
    @James the start of that line is "Inside a class" - so no, it is not true that everything is `internal`. It is, as stated correctly, `private`. – Marc Gravell Nov 04 '13 at 12:30
  • @peter Downvoting is a common way to draw attention to a possible duplicate question. It's not necessarily an indication that there is anything wrong with the question. – David Arno Nov 04 '13 at 12:38
  • @peter: You accepted an answer that offers no more information than what already exists in the proposed duplicate. What does this say about this question? – Jon Nov 04 '13 at 12:48

1 Answers1

1

Please have a read of http://msdn.microsoft.com/en-us/library/ms173121.aspx

Struct members, including nested classes and structs, can be declared as public, internal, or private. Class members, including nested classes and structs, can be public, protected internal, protected, internal, or private. The access level for class members and struct members, including nested classes and structs, is private by default. Private nested types are not accessible from outside the containing type.

(emphasis mine).

David Arno
  • 42,717
  • 16
  • 86
  • 131