Sunday, April 18, 2010

What are the access modifiers C# supports and their purpose?

2 comments:

Jasmine said...

C# supports following access modifiers:

Public - Access not limited. The type or member can be accessed by any other code in the same assembly or another assembly that references it.

Private - Access limited to the containing class.The type or member can only be accessed by code in the same class or struct.

Protected - Access limited to the containing class and to the types derived from the containing class. The type or member can only be accessed by code in the same class or struct, or in a derived class.

Internal - Access limited to this- program or assembly.The type or member can be accessed by any code in the same assembly, but not from another assembly.

Protected Internal - Access limited to the containing class, derived classes members or assembly.The type or member can be accessed by any code in the same assembly, or by any derived class in another assembly.

Isha said...

C# supports
Public
private
protected
Internal

Default is Internal(which is throughout the assembly) at class level
Default is private for all methods and variables.