类的使用(Use of classes)

类的成员:字段、属性、方法

字段:a.字段主要是为类的内部做数据交互使用,字段一般是private。           b.字段可读可写。           c.当字段需要为外部提供数据的时候,请将字段封装为属性,而不是使用公有字段(public修饰符),这是面向对象思想所提倡的。

属性:a.属性一般是向外提供数据,主要用来描述对象的静态特征,所以,属性一般是public。           b.属性具备get(只读)和set(只写)方法,可以在方法里加入逻辑处理数据,灵活拓展使用。

方法: 声明:(访问修饰符) <类型> <方法名>{方法体}            调用:[<类名.>]|[<实例对象名.>]<方法名>([<实参列表>])            定义:是类中用于执行计算或其它行为的成员

类的成员的访问性:a、public :访问不受限制。            b、protected :访问仅限于包含类或从包含类派生的类型。                                 c、internal :访问仅限于当前程序集。                                 d、protected internal :访问仅限于从包含类派生的当前程序集或类型。                                 e、private :访问仅限于包含类。

————————

Class members: fields, properties, methods

Fields: A. fields are mainly used for data interaction within classes. Fields are generally private.             b. Fields are readable and writable.             c. When a field needs to provide external data, please encapsulate the field as an attribute instead of using a public field (public modifier), which is advocated by the object-oriented idea.

Attributes: A. attributes generally provide data to the outside world, and are mainly used to describe the static characteristics of objects. Therefore, attributes are generally public.             b. Property has get (read-only) and set (write only) methods. Logic can be added to the method to process data, which can be used flexibly.

Method: Declaration: (access modifier) & lt; Type & gt& lt; Method name & gt; {method body}             Call: [& lt; class name. & gt;] | [& lt; instance object name. & gt;] & lt; Method name & gt; ([& lt; argument list & gt;])             Definition: a member of a class used to perform calculations or other actions

Accessibility of class members: A. public: unrestricted access.              b. Protected: access is limited to containing classes or types derived from containing classes.                                   c. Internal: access is limited to the current assembly.                                   d. Protected internal: access is limited to the current assembly or type derived from the containing class.                                   e. Private: access is limited to containing classes.