All articles(网络文学目录) All Pictures(图片目录) All Softwares(软件目录)

 
C#教程:C#中的显示类型转换

Writer: qq Article type: Programming skills(编程技巧) Time: 2014/7/11 9:21:32 Browse times: 350 Comment times: 0

C#教程:C#中的显示类型转换


Head photo

Go homepage
Upload pictures
Write articles

C#教程:C#中的显示类型转换

显示类型转换
显示类型转换是指将高精度数值转换为低精度数值,必须指明将要转换的目标类型。由于数据类型的差异,有可能丢失部分数据。
示例
本教程来自http://www.isstudy.com
double类型x的显示类型转换
下面的示例代码演示了如何将x进行显示类型转换。
class Test
{
static void Main()
{
double x = 1234.7;
int a;
a = (int)x; // cast double to int
System.Console.WriteLine(a);
}
}
输出结果:
1234

也可以用Convert关键字进行数据类型强制转换。例如:
Double MyDouble = 42.72;
int MyInt =Convert.ToInt32(MyDouble);

完整程序代码如下:
★★★★★主程序文件完整程序代码★★★★★
using System;
using System.Collections.Generic;
using System.Text;
namespace _2_03
{
class Program
{
static void Main(string[] args)
{
double x = 1234.7;
int a;
a = (int)x; // cast double to int
System.Console.WriteLine(a);
}
}
}





There are 0 records,
Comment:
Must be registered users to comment(必须是注册用户才能发表评论)

Disclaimer Privacy Policy About us Site Map
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.