What is the default access specifier in c#

  • Context: C# 
  • Thread starter Thread starter chandubaba
  • Start date Start date
Click For Summary

Discussion Overview

The discussion centers around the default access specifier in C#, exploring the distinctions between access levels for classes and class members. Participants reference various sources and interpretations of the rules governing access specifiers in the language.

Discussion Character

  • Debate/contested

Main Points Raised

  • One participant states that the default access specifier for a class is internal, while for class members, it is private, citing conflicting information from different sources.
  • Another participant confirms that things declared outside of a class or struct default to internal, whereas those declared inside default to private.
  • A third participant provides a link to a resource detailing C# access specifiers, suggesting further reading.
  • A later reply references documentation indicating that top-level types can only have internal or public accessibility, with internal being the default.

Areas of Agreement / Disagreement

Participants express differing views on the default access specifiers, with some asserting that class members default to private and others suggesting that everything is private. The discussion remains unresolved regarding the specifics of default access levels.

Contextual Notes

There are references to various sources, but the discussion highlights potential confusion regarding the definitions and contexts of access specifiers in C#.

chandubaba
Messages
39
Reaction score
0
Hello,
what is the default access specifier in c#. In college everyone says its private, but in the textbook its written "When you do not specify any data member as public, protected or private the default access specifier for a class is internal."

And in one forum I read that default access specifier for class is internal but for class members is private. But again in the same forum someone says everything is private. Which is correct?
 
Technology news on Phys.org
Things declared outside of a class or struct will default to internal. Things declared inside of a class or struct will default to private.
 

Similar threads

  • · Replies 36 ·
2
Replies
36
Views
3K
  • · Replies 25 ·
Replies
25
Views
3K
  • · Replies 34 ·
2
Replies
34
Views
4K
  • · Replies 23 ·
Replies
23
Views
3K
  • · Replies 25 ·
Replies
25
Views
6K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 9 ·
Replies
9
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K