好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

C#数据类型转换.doc

5页
  • 卖家[上传人]:cn****1
  • 文档编号:539715591
  • 上传时间:2023-09-08
  • 文档格式:DOC
  • 文档大小:21.50KB
  • / 5 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • C#数据类型转换在应用程序编程时,数据类型转换是常见的,各种编程语言都是重要的内容这里考虑整型、实型、字符串型、日期型之间的转换bool型不需要转换,其它类型则更为复杂对象和变量之间的转换则是“装箱”“拆箱”基本的方法为3种:直接赋值 在数值型之间都可以这样,但有可能丢失数据用类型中的ToString()方法,或Parse()等方法用系统的Convert对象,该对象就是进行类型转换的有些情况,几种方法都可以实现1 int long float double 直接赋值就可以2 数值型转string,都可以用ToString() 如: 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 = " + d.ToString() + "\n"); this.textBox1.AppendText("float e = " + e.ToString() + "\n"); this.textBox1.AppendText("double f = " + f.ToString() + "\n");3 string转字符 int x; long y; float p; double q; string str="50"; x = int.Parse(str); y = long.Parse(str); p = float.Parse(str); q = double.Parse(str);==========================================4 Convert对象ToInt32(); //转换成32位的整数ToInt16(); //转换成16位的整数ToBoolean(); //转换成 bool 值ToString(); //转换成 字符串ToDouble(); //转换成小数例:double x; string str=”30”; x = Convert.ToDouble(str);5 整型和日期的转换因为日期是由整数的成员构成的,所以通过成员的读写就可以。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.