首页 > 其他 > 详细

类型基础

时间:2015-06-10 13:57:54      阅读:227      评论:0      收藏:0      [点我收藏+]

变量是存储位置的符号 ,它包含的值可以变化。常量的值则一直保持不变

const int y = 365;

预定义类型

  预定义类型是编译器支持的类型 比如 int   string  bool.

  System 命名空间下 DateTime 不是内置类型。

自定义类型

    using System;

  public class UnitConverter{

      int ratio;   //字段

  public UnitConverter(int unitRatio) {ratio = unitRatio;} //构造方法

 public int Convert(int unit) {return unit * ratio;}  //方法

}

class Test{

   static void Main(){

      UnitConverter a = new UnitConverter(10);

       UnitConverter b = new UnitConverter(100);

          a.Convert(100);

          b.Convert(10);

    }

}

类型转换

    int x = 1234;

   long y = x ;  隐士转换    long 大于 int

 short z = (short)x;  显示抓换

 值类型 和 引用类型

    值类型

    引用类型

    泛型参数

    指针类型

值类型 : 内置类型 struct 类型 enum 类型

引用类型: 类,接口 委托

NULL

  引用类型可以赋值 null 表示没指向任何对象。

存储开销

值类型 正好期字段占得内存

引用类型 除了字段的开销还有额外管理占用的开销。

 

 

预定义类型分类

    值类型

        数值

        bool

        字符

    引用类型

      字符串 string

      对象  object

 预定义类型也叫框架类型 都在 system 命名空间下

   int i = 5;   System.Int32 i =5;

 

类型基础

原文:http://www.cnblogs.com/hlhxd/p/4565806.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!