C # Basics (i) access modifiers, ref and out, flag enumeration, and moreOne, access modifiersThe
access modifiers in C # are :private,protected,internal, Publicpublic: Common type, the same assembly or other assembly can access this member Private: This member can be accessed in the same class or struct .protected: Protection type, in the same class or derived class, can access this memberinternal: Internal type, only the same assembly can access this member
Accessibility inconsistency: the child class cannot have access to a higher level than the parent class. Prevent exposing the parent class information:
ii. The difference between static, const and readonly
Static: Statically, shared, can be changed, defined when not assigned, defaults to the default value of type; applies to
multiple instances of a class share a property or field .
Const:
You must assign a value when you define it, and you cannot change it later.
readonly: After declaration, you can
assign a value when it is initialized or defined in the constructor, and the instance object cannot be modified. third,
ref and out1,
ref before use, you must first assign a value. The
out parameter must be assigned in the method that is called, so it doesn't make sense to assign a value even before it is passed;2, when a method to return multiple values at the same time, you can consider the use of out parameters;3, ref is to take a value in, and then bring out. Out is not brought in, brought out. four, variable parameters: Param
1. The variable parameter can only be placed in the last position of the parameter list;2. You can pass 1 values, you can pass a multi-value, or you can not pass the value. Variable parameter is not null;3. If the length of the pass is a value of 0, the
variable parameter array is an array of length 0, but not null. v. Value types and reference types1. All
reference types inherit from
Object, and all
value types inherit from System.
ValueType; 2. Assign a value to a reference type object, copy only the application to the object, assign a value type object, and copy the copy to him;3. For value types: The data stored in the stack is directly used. For reference types: The address of the object in the heap is stored in the stack. Vi. enumeration and flag enumeration [flags]
features of the general enumeration:1.
Each value of the general enumeration is mutually exclusive ;2. Each value of the enumeration is represented by a corresponding value. You can set the corresponding integer manually. are generally substituted with int;3. After compiling, the enumeration is represented by the corresponding data constants;4. The value in the enumeration can be converted to a string. ToString () method.
flag enumeration [flags]:1. You can assign multiple enumeration values at the same time, such as the file's attribute xx
| xxx;2. Flag enumeration to be preceded by the definition,
plus [flags] : representation,. ToString returns a literal form, not a number. The assignment can be done by |;3. Verify that there is a number for this enumeration, which
can take the IF (enumeration variable & enum. Value) = = enumeration. Value 7. Object-orientedthree main features of object-oriented: encapsulation, inheritance, polymorphismObject-oriented principle: open for extensions, close for modifications. reprinted from: Http://www.cnblogs.com/polk6/archive/2012/10/03/2710864.html
C # Basics (i) access modifiers, ref and out, flag enumeration, and more