0
0
C Sharp (C#)programming~5 mins

Access modifiers (public, private, internal) in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the public access modifier mean in C#?
The <strong>public</strong> modifier means the member or class is accessible from anywhere in the program or other programs that reference it. It's like a door open to everyone.
Click to reveal answer
beginner
What is the purpose of the private access modifier?
The <strong>private</strong> modifier restricts access to the member or class so it can only be used inside the same class. Think of it as a secret only the class knows.
Click to reveal answer
intermediate
Explain the internal access modifier in C#.
The internal modifier allows access only within the same assembly (project). It's like a private room shared only with people in the same building.
Click to reveal answer
beginner
Which access modifier is the default for class members if none is specified?
If no access modifier is specified for class members, the default is <strong>private</strong>. So, members are hidden unless you say otherwise.
Click to reveal answer
beginner
Can a <strong>private</strong> member be accessed from another class in the same assembly?
No, <strong>private</strong> members are only accessible inside their own class, even if another class is in the same assembly.
Click to reveal answer
Which access modifier allows a class member to be accessed from any other code in the same assembly or another assembly?
Apublic
Bprivate
Cinternal
Dprotected
What is the default access level for members of a class if no modifier is specified?
Aprotected
Bpublic
Cinternal
Dprivate
Which access modifier restricts access to the same assembly only?
Ainternal
Bpublic
Cprivate
Dprotected internal
Can a private member be accessed from a derived class?
AYes, always
BNo, never
CYes, if in the same assembly
DOnly if marked protected
Which modifier would you use to allow access only within the same class and derived classes?
Apublic
Bprivate
Cprotected
Dinternal
Describe the differences between public, private, and internal access modifiers in C#.
Think about who can open the door to the member or class.
You got /3 concepts.
    Explain why you might choose to use private instead of public for a class member.
    Consider keeping secrets safe inside a class.
    You got /3 concepts.