Define encapsulate class type

来源:互联网 发布:如何查看淘宝卖家资质 编辑:程序博客网 时间:2024/06/06 11:00

 

Encapsulation: encapsulate implement details and hide data.

Inheritance: inherit base class's function and extend base class's behavior

Polymorphism: interface, virtual, abstract, override.

 

 

Public, private, protected, internal(access only in current program set), protected internal.

Nested type:

Public class SportsCar

{

  private enum CarColor

  {

    Red, Green, Blue

  }

}

Use class type to encapsulate:

class Employee

{

private string empName;

public string Name

{

get { return empName; }

set{ empName=value; }

}

}

 

Each property hide get_XXX()/set_XXX() method inner CLR, so cannot add this method in current class.

Use property accessor to define a read-only or write-only property.

Static constructor function: initial static data.

 

Const type, readonly type.

Class MyMathClass

{

  public readonly double PI;

   public MyMathClass()

  {

    PI=3.14;

  }

}

 

Class MyMathClass

{

  public static readonly double PI;

   static MyMathClass()

  {

    PI=3.14;

  }

}

 

Partial class Employee{}