C#编程:定义类成员-定义字段
在类定义中也提供了类成员的定义.此篇说下定义类字段.定义类字段时要用到关键字.
分别为:public, private, internal, protected, static, readonly
Public : 成员可以由任何代码访问
ptivate : 成员只能由类中的代码访问.如果没有使用任何关键字默认就是使用这个
internal : 成员只能由定义它的项目内部的代码访问
protected : 成员只能能由类或派生类中的代码访问
static : 声明类的静态成员
readonly : 声明类的成员只能在执行构造函数的过程中赋值
代码:

  1. class Myclass
  2.         {
  3.             public int MyInt = 1;
  4.             private int MyInt2 = 2;
  5.             internal int MyInt3 = 3;
  6.             protected int MyInt4 = 4;
  7.             public readonly int MyInt5 = 5;
  8.             public static int MyInt6 = 6;
  9.         }

Read the rest of this entry »

, , , , , , , , ,