C#数据类型

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().

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值