Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Internal vs. Private Access Modifiers

What is the difference between the internal and private access modifiers in C#?

like image 861
Jim Fell Avatar asked Sep 28 '10 13:09

Jim Fell


People also ask

What is internal access modifier?

Internal is one of the access modifiers that limits the access to types defined within the current project assembly. The default accessibility of classes and structs that are declared within a namespace or at the top level of a compilation unit and not within other types is internal.

What are the differences between public internal protected and private modifiers?

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.

What are the 3 types of access modifiers?

Access Modifiers in Java are used to define the accessibility of methods and data members. There are four main types of Access Modifiers – Default, Private, Protected, and Public.

When should you use private access modifiers?

Private: The private access modifier is specified using the keyword private. The methods or data members declared as private are accessible only within the class in which they are declared. Any other class of the same package will not be able to access these members.


2 Answers

internal is for assembly scope (i.e. only accessible from code in the same .exe or .dll)

private is for class scope (i.e. accessible only from code in the same class).

like image 116
explorer Avatar answered Oct 23 '22 06:10

explorer


Find an explanation below. You can check this link for more details - http://www.dotnetbull.com/2013/10/public-protected-private-internal-access-modifier-in-c.html

Private: - Private members are only accessible within the own type (Own class).

Internal: - Internal member are accessible only within the assembly by inheritance (its derived type) or by instance of class.

enter image description here

Reference :

dotnetbull - what is access modifier in c#

like image 28
Vivek Avatar answered Oct 23 '22 06:10

Vivek