2006-11-21

C#.NET 中的类型转换

来源: 本站收集整理 作者:佚名 评论 0 条
 ""; this.textBox1.AppendText("byte -> " a.GetType().FullName "n"); this.textBox1.AppendText("char -> " b.GetType().FullName "n"); this.textBox1.AppendText("short -> " c.GetType().FullName "n"); this.textBox1.AppendText("int -> " d.GetType().FullName "n"); this.textBox1.AppendText("long -> " e.GetType().FullName "n"); this.textBox1.AppendText("uint -> " f.GetType().FullName "n"); this.textBox1.AppendText("bool -> " g.GetType().FullName "n"); }

  在窗体中新建一个按钮,并在它的单击事件中调用该 TestAlias() 函数,我们将看到运行结果如下:

byte -> System.Byte
char -> System.Char
short -> System.Int16
int -> System.Int32
long -> System.Int64
uint -> System.UInt32
bool -> System.Boolean

  这足以说明各别名对应的类!

2. 数值类型之间的相互转换

  这里所说的数值类型包括 byte, short, int, long, fload, double 等,根据这个排列顺序,各种类型的值依次可以向后自动进行转换。举个例来说,把一个 short 型的数据赋值给一个 int 型的变量,short 值会自动行转换成 int 型值,再赋给 int 型变量。如下例:

private void TestBasic() {

    byte a = 1; short b = a; int c = b;

    long d = c; float e = d; double f = e;

    this.textBox1.Text = "";

    this.textBox1.AppendText("byte a = "   a.ToString()   "n");

    this.textBox1.AppendText("short b = "   b.ToString()   "n");

    this.textBox1.AppendText("int c = "   c.ToString()   "n");

    this.textBox1.AppendText("long d = "


共10页: 上一页 [1] 2 [3] [4] [5] [6] [7] [8] [9] [10] 下一页
(本文仅表明作者个人观点,不代表本站及其管理员立场.) 推荐 收藏 投稿 打印 返回 关闭
上一篇:登陆页优化的七大规则  
下一篇:ASP.NET 2.0高级数据处理之主从数据表
    评论加载中…
 推荐文章
     

网站首页  -  网站地图 -   站长论坛  -  网站投稿  -    -  网站管理
Copyright © 2008 芜湖站长站 All Rights Reserved 皖ICP备07500611号