Access Modifiers

Class and Member Modifiers Class Access Modifiers The default access modifier of a class is internal. That means the class accessible from other classes in the same assembly. By default mean that this is the access provided if you include no access modifier keyword. Thus, these two are equivalent: class MyClass { ... } internal class MyClass { ... } The default internal access is appropriate for the vast majority of classes you will create. A public class is accessible without restri

Class and Member Modifiers
Class Access Modifiers
The default access modifier of a class is internal. That means the class accessible from other classes in the same assembly. By default mean that this is the access provided if you include no access modifier keyword. Thus, these two are equivalent:
class MyClass { ... }
internal class MyClass { ... }
The default internal access is appropriate for the vast majority of classes you will create.
A public class is accessible without restriction. It means that a public class in one assembly is accessible from another assembly.
public class MyClass { ... }
The most restrictive class access is created with the private keyword. You can use private only with a nested class, one that is defined within another class.
public class OuterClass
{
...
private class InnerClass
{
}
}

A class defined using the abstract keyword cannot be instantiated. Thus if you have a class definition like this :
abstract class MyClass { ... }

Abstract classes are usually created to serve as base classes.

A sealed class is sort of the opposite of abstract.

Member Access Modifiers
By default, class members are private, which means they are accessible only from code in the class.
MyMethod() { ... }
private MyMethod() { ... }
Slightly less restrictive is protected access, obtained with the (you guessed it) protected keyword. A protected member is accessible in the type in which it is defined and in types derived from that type:
protected MyMethod() { ... }

Thus, if you create a protected member in class A and then create class B that inherits from A, the member will be available to code in class B.
Internal access means the member is accessible to other types that are defined in the same assembly:
internal MyMethod() { ... }
You can combine the protected and internal keywords to provide member access that is a combination of the two:
protected internal MyMethod() { ... }
The least restrictive access is obtained with the public keyword. Use the public keyword to make a class member freely accessible inside and outside of the class.
public internal MyMethod() { ... }

By Web Star   Popularity  (1751 Views)
Biography - Web Star
Visit my Blog Web developer using Asp.net,C#.net,Sql Server, Silverlight, Javascript, CSS, AJAX etc.