By the eggs from pregnant UC # graphic tutorials study notes - or related concepts

By the eggs from pregnant U█ Micro Signal █: 138 • 0226 • 9370█ █ successful surrogacy package bag pack healthy sex surrogate █ ██ bag boy

Graphic tutorial to learn C # notes - or related concepts

 

First, some basic concepts
1. Field: variables belonging to the class, i.e. the class member variable.
2. Method: function, member function belongs to the class, that class.
3. Examples of members: Each instance of a class has its own copy of each class member, these members are called instance members. An example of changing the value of the field does not affect the value of any other instance member of.
4. Static member
Static members are related to the class members, is loaded into the static storage area, and is only created once, all instances of a class share static members.
Static fields Example:

Static member function: no instances of the class can call the static method. Static member function can not access instance members, can only access static members.
From external access static member classes: static member class name Name
Note:
  Examples of static member even if there is no class. If the static field initialization statement, it will initialize the field before using any static member of the class, but not necessarily at the beginning of the implementation of the program will be initialized.
5. Members constants: Constants in the class declaration statement.
Constants can not be declared as static members.
Constant members behave like static values for each instance of the class are visible, even if there is no instance of the class can access. But constant not have their own storage location, but is replaced by the compiler at compile time, while static amount have their own storage location.
6. readonly modifiers: Available readonly field modification. Its role is similar to a field declared const, can not be changed once the value is set.
What is the difference between const and readonly field field?
(1) const field can only be initiated in a field declaration statement, and readonly field can be initialized in the field in addition to the declaration statement, it can also be initialized in the constructor of any class, if the field is static initialization must be done in a static constructor .
(2) const field values must be determined at compile time, while readonly field value can be determined at run time.
(3) behavior is always static const field, there is no storage location in memory. The field may be a static readonly field, instance field may be, but is in memory storage location.

 

Second, the properties of
a data item class instance attributes represent member or class. Use read or write property looks like a field, they are the same syntax.
1. The characteristic properties on a number of
(1) attribute type is named class members, may be assigned and read.
(2) attribute code execution, data storage is not allocate memory.
(3) may be declared as static.
(4) The method has two attributes called an access device to:
<. 1> SET accessor: attribute assigned. Has a separate, implicit reference value, the name of value, given the same type of property, the return type of void.
<2> get accessor: the value of a property. No parameters and returns the same type as the property type.
Accessor set, get in any order, in addition to these two accessor method does not allow other extrinsic attributes.
Accessor set, get to define only one, but at least to define a.
Example:

2. The use of the attribute
properties according to the operation currently executed is read or write, invoke implicit accessor. (Access can not be invoked explicitly)
Example:

3. The role of property
(1) In the packaging field is declared as private field, and declare a public property to control the access from outside the class's fields. This field often referred to as back-up field, backing store.
(2) can be declared as read-only or write-only property, to control the backing field is read-only or write-only. Only get accessor property is read only, only the set accessor property is write-only property.
(3) Access attribute may perform other calculations for the field.
4. automatically properties
because the properties are often associated backing field, C # properties provided automatically (automatically implemented property), allowing only the declaration statement attributes without backing field. The compiler creates a hidden backing field for you, and get hooked up to the field and set accessor. 
Important attributes automatically as follows:
(1) no backing field declaration, compiler allocates memory according to the attribute type.
(2) does not provide an access method body, they must be simply declare a semicolon. get the equivalent of a simple memory read, set equivalent to simply write.
(3) except through access control, or can not access the backing field. Because it can not access any other way, so to achieve a read-only and write-only property has no meaning, so using automatic properties must also provide read and write access device.

 

Third, Constructors
1. Name the same as the class constructor.
2. constructor can not return a value.
3. If no explicit instance constructor is provided in the class declaration, the compiler provides an implicit default constructor, a default constructor without parameters, and the method body is empty.
4. As long as declared constructor, the compiler will no longer provide a default constructor.
The constructors can be overloaded.
Example 6. Each instance of a new class constructor initializes static constructor initializes the class-level item. Typically, the static constructor initializes static field class.
7. The static constructor is not explicitly called in the program, the system will automatically call them, call timing: before any class instance is created; any static member of the class is referenced before.

 

Fourth, the indexer
index is a set of get and set accessor, with similar properties. It is believed that the index is to provide a get, set attributes for multiple data members of the class.
Example declaration:

调用示例:
var emp = new Employee();
emp[0] = "Jet";
emp[1] = "Wu";
var lastname = emp[0];
1. 和属性一样,索引器不用分配内存来存储。
2. 和属性一样,索引器可以只有一个访问器,也可以两个都有。
3. 索引器总是实例成员,因此不能声明为static。
4. 和属性一样,实现get、set访问器的代码不必一定关联到某字段或属性。这段代码可以什么都不做,只要get访问器返回某个指定类型值即可
5. 索引器声明中,参数列表至少要声明一个参数。
6. 和属性一样,不能显示调用get、set访问器。取而代之,当索引器用在表达式中取值时,将自动调用get访问器。索引器被赋值时,自动调用set访问器。 
7. 索引器重载:一个类可以有任意多个参数列表不同的索引器。
8. 索引器的访问修改符:
(1)仅当成员(属性或索引器)既有get访问器也有set访问器时,其访问器才能有访问修饰符。
(2)虽然两个访问器都必须出现,但它们中只能有一个有访问修饰符。
(3)访问器的访问修饰符必须比成员的访问级别有更严格的限制性,即访问器的访问级别必须比成员的访问级别低。

 

五、分部类和分部方法
1. 分部类
类的声明可以分割成几个分部类的声明。
每个分部类的声明都含有一些类成员的声明。
类的分部类声明可以在同一文件中也可以在不同文件中
每个局部声明必须标为partial class,而不是class。
分部类声明看起来和普通类声明相同。
示例:

2. 分部方法
分部方法是声明在分部类中不同部分的方法。
分部方法分为两个部分:定义分部方法声明和实现分部方法声明。
1. 定义声明和实现声明的签名和返回类型必须匹配。签名和返回类型有如下特征:
<1>返回类型必须是void。
<2>签名不能包括访问修饰符,这使分部方法是隐式私有的。
<3>参数列表不能包含out参数。
<4>在定义声明和实现声明中都必须包含上下文关键字partial,直接放在关键字void前。
2. 可以有定义部分而没有实现部分。这种情况下,编译器把方法的声明以及方法内部任何对方法的调用都移除。不能只有实现部分而没有定义部分。
示例:

 

 
分类:  C#

一、一些基本概念
1. 字段:隶属于类的变量,即类的成员变量。
2. 方法:隶属于类的函数,即类的成员函数。
3. 实例成员:类的每个实例拥有自己的各个类成员的副本,这些成员称为实例成员。 改变一个实例字段的值不会影响任何其他实例成员中的值。
4. 静态成员
静态成员是与类相关的成员,被加载到静态存储区,且只被创建一次,类的所有实例共享静态成员。
静态字段示例:

静态函数成员:无需类实例就可以调用静态方法。静态函数成员不能访问实例成员,只能访问静态成员。
从类的外部访问静态成员:类名称.静态成员名称
注:
  静态成员即使没有类的实例也存在。如果静态字段有初始化语句,那么会在使用该类的任何静态成员之前初始化该字段,但没必要在程序执行的开始就初始化。
5. 成员常量:声明在类声明中的常量。
常量不能声明为静态成员。
成员常量表现得像静态值,对类的每个实例都是可见的,即使没有类的实例也可以访问。但是常量没有自己的存储位置,而是在编译时被编译器替换,而静态量是有自己的存储位置的。
6. readonly修饰符:字段可用readonly修饰。其作用类似于将字段声明为const,一旦值被设定就不能改变。
readonly字段与const字段有何区别?
(1)const字段只能在字段声明语句中初始化,而readonly字段除了可以在字段声明语句中初始化,还可以在类的任何构造函数中初始化,如果是static字段,初始化必须在静态构造函数中完成。
(2)const字段的值必须在编译时决定,而readonly字段值可以在运行时决定。
(3)const字段的行为总是静态的,在内存中没有存储位置。而readonly字段可以是静态字段,也可以是实例字段,而且在内存中是有存储位置的。

 

二、属性
属性代表类的实例或类中的一个数据项成员。使用属性看起来像写入或读取一个字段,它们语法相同。
1. 关于属性的一些特性
(1)属性是有类型的、命名的类成员,可以被赋值和读取。
(2)属性是执行代码,不为数据存储分配内存。
(3)可被声明为static。
(4)属性拥有两个称为访问器的方法:
<1>set访问器:为属性赋值。拥有一个单独的、隐式的值参,名称为value,与属性的类型相同,返回类型为void。
<2>get访问器:从属性取值。没有参数,返回类型与属性类型相同。
访问器set、get顺序任意,除这两个访问器外在属性上不允许有其他方法。
访问器set、get可以只定义其中一个,但至少要定义一个。
示例:

2. 属性的使用
属性根据当前执行的操作是写入还是读取,隐式调用访问器。(访问器不能被显式调用)
示例:

3. 属性的作用
(1)将字段声明为private以封装字段,并声明一个public属性来控制从类的外部对该字段的访问。这样的字段常被称为后备字段、后备存储。
(2)可以声明属性为只读或只写,从而控制后备字段为只读或只写。只有get访问器的属性为只读属性,只有set访问器的属性为只写属性。
(3)属性访问器可以对字段执行其他计算。
4. 自动实现属性
因为属性经常关联到后备字段,C#提供了自动实现属性(automatically implemented property),允许只声明属性而不声明后备字段。编译器为你创建隐藏的后备字段,并且字段挂接到get和set访问器上。 
自动实现属性的要点如下:
(1)不声明后备字段,编译器根据属性类型分配存储。
(2)不能提供访问器的方法体,它们必须被简单地声明为分号。get相当于简单的内存读,set相当于简单的写。
(3)除非通过访问器,否则不能访问后备字段。因为不能用其他方法访问,所以实现只读和只写属性没有意义,因此使用自动属性必须同时提供读写访问器。

 

三、构造函数
1. 构造函数的名称与类相同。
2. 构造函数不能有返回值。
3. 如果在类的声明中没有显式的提供实例构造函数,那么编译器会提供一个隐式的默认构造函数,默认构造函数没有参数,且方法体为空。
4. 只要声明了构造函数,编译器就不再提供默认构造函数。
5. 构造函数可以被重载。
6. 实例构造函数初始化类的每个新实例,静态构造函数初始化类级别的项。通常,静态构造函数初始化类的静态字段。
7. 静态构造函数不能在程序中显式调用,系统会自动调用它们,调用时机:类的任何实例被创建前;类的任何静态成员被引用前。

 

四、索引器
索引器是一组get和set访问器,与属性类似。可以认为,索引器是为类的多个数据成员提供了get、set属性。
声明示例:

调用示例:
var emp = new Employee();
emp[0] = "Jet";
emp[1] = "Wu";
var lastname = emp[0];
1. 和属性一样,索引器不用分配内存来存储。
2. 和属性一样,索引器可以只有一个访问器,也可以两个都有。
3. 索引器总是实例成员,因此不能声明为static。
4. 和属性一样,实现get、set访问器的代码不必一定关联到某字段或属性。这段代码可以什么都不做,只要get访问器返回某个指定类型值即可
5. 索引器声明中,参数列表至少要声明一个参数。
6. 和属性一样,不能显示调用get、set访问器。取而代之,当索引器用在表达式中取值时,将自动调用get访问器。索引器被赋值时,自动调用set访问器。 
7. 索引器重载:一个类可以有任意多个参数列表不同的索引器。
8. 索引器的访问修改符:
(1)仅当成员(属性或索引器)既有get访问器也有set访问器时,其访问器才能有访问修饰符。
(2)虽然两个访问器都必须出现,但它们中只能有一个有访问修饰符。
(3)访问器的访问修饰符必须比成员的访问级别有更严格的限制性,即访问器的访问级别必须比成员的访问级别低。

 

五、分部类和分部方法
1. 分部类
类的声明可以分割成几个分部类的声明。
每个分部类的声明都含有一些类成员的声明。
类的分部类声明可以在同一文件中也可以在不同文件中
每个局部声明必须标为partial class,而不是class。
分部类声明看起来和普通类声明相同。
示例:

2. 分部方法
分部方法是声明在分部类中不同部分的方法。
分部方法分为两个部分:定义分部方法声明和实现分部方法声明。
1. 定义声明和实现声明的签名和返回类型必须匹配。签名和返回类型有如下特征:
<1>返回类型必须是void。
<2>签名不能包括访问修饰符,这使分部方法是隐式私有的。
<3>参数列表不能包含out参数。
<4>在定义声明和实现声明中都必须包含上下文关键字partial,直接放在关键字void前。
2. 可以有定义部分而没有实现部分。这种情况下,编译器把方法的声明以及方法内部任何对方法的调用都移除。不能只有实现部分而没有定义部分。
示例:

 

Guess you like

Origin www.cnblogs.com/DENG012/p/10947748.html