Modifiers in C#
modifiers — keywords that can be applied to a type or to a member.
Access Modifiers: public - The item is visible to any other code.
protected - The item is visible only to any derived type. internal - The item is visible only within its containing assembly. private - The item is visible only inside the type to which it belongs. protected internal - The item is visible to any code within its containingassembly and also to any code inside a derived type.
Example: public class MyClass{// etc.}
Modifiers that indicate the nature of an item:
Abstrac t- Indicates that a class is intended only to be a base class of other classes. Const - Specifies that the value of the field or the local variable cannot be modified. New- Hides an inherited member from a base class member. Override - Provides a new implementation of a virtual member inherited from a base class.
Partial - Defines partial classes, structs and methods throughout the same assembly.
Sealed - Specifies that a class cannot be inherited.
Static - Declares a member that belongs to the type itself instead of to a specific object.
Virtua l - Declares a method or an accessor whose implementation can be changed by an overriding member in a derived class.
extern -The member is implemented externally, in a different language.
class MyBaseClass {
public virtual string VirtualMethod() {
return "This method is virtual and defined in MyBaseClass"; } }
class MyDerivedClass: MyBaseClass {
public override string VirtualMethod() {
return “This method is an override defined in MyDerivedClass.”; } }
Дата добавления: 2015-09-18 | Просмотры: 507 | Нарушение авторских прав
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 |
|