标签:
类和结构体都包括数据和操作数据的方法
类的定义形式
class PhoneCustomer
{
public const string DayOfSendingBill = "Monday";
public int CustomerID;
public string FirstName;
public string LastName;
}
结构体和类的区别在于:结构体是在内存中存储和访问的(类是引用类型存储在托管堆中,结构体是值类型存储在栈中,不支持继承)
结构体的定义形式如下:
struct PhoneCustomerStruct
{
public const string DayOfSendingBill = "Monday";
public int CustomerID;
public string FirstName;
public string LastName;
}
实例化的时候都需要使用new关键字,形式如下:
PhoneCustomer myCustomer = new PhoneCustomer(); // works for a class
PhoneCustomerStruct myCustomer2 = new PhoneCustomerStruct();// works for a struct
完整的结构体定义形式如下
struct Dimensions
{
public double Length;
public double Width;
public Dimensions(double length, double width) //构造函数
{
Length = length;
Width = width;
}
}
未完待续......
标签:
原文地址:http://www.cnblogs.com/tianmochou/p/4964052.html