1. C#支持Common Type System(CTS),其中的数以势压人类型集合不公包含我们熟悉的基本类型,还包括比较复杂的类型.
2. 类型的安全:
必须使用显式的语句进行显式的转换.
值类型和引用类型实例: (简言:类为引用类型;结构为值类型)
using System;
class RefTypeRectangle
{
public int Width;
public int Height;
}
struct VarTypeRectangle
{
public int Width;
public int Height;
}
class RefValTest
{
public static int Main ()
{
RefTypeRectangle rect1=new RefTypeRectangle();
rect1.Width=10;
rect1.Height=15;
RefTypeRectangle rect2=rect1;
Console.WriteLine("Dimensions of rect2 are"+rect2.Width+"x"+rect2.Height);
rect1.Width=20;
rect1.Height=25;
Console.WriteLine("Dimeasions of rect2 now are"+rect2.Width+"x"+rect2.Height);
VarTypeRectangle rect3=new VarTypeRectangle();
VarTypeRectangle rect4=rect3;
Console.WriteLine("Dimensions of rect4 are"+rect4.Width+"x"+rect4.Height);
rect3.Width=20;
rect3.Height=25;
Console.WriteLine("Dimensions of rect4 now are"+rect4.Width+"x"+rect4.Height);
return 0;
}
}
引用类型的创建:需用new关键字把该引用指向保留堆中的一个对象,如下:
Something objSomething
objSomething=new Something();
C#支持两个预定义的引用类型:object , string
一 Object类型:是从所有内在和用户定义的类型中派生而来的最终父类型,可以使用它引用绑定任何特定子类型的对象.并执行许多基本的一般用途的方法,包括Equals(),GetHashCode(),GetType(),ToString().