C#中的Convert.ChangeType方法
该ChangeType()方法返回指定类型的对象,其值等于指定的对象。
假设我们有一个double类型。
double val = -3.456
现在,使用ChangeType方法将类型更改为整数。
num = (int)Convert.ChangeType(val, TypeCode.Int32);
让我们看完整的例子。
示例
using System;
public class Demo {
public static void Main() {
double val = -3.456;
int num = (int)Convert.ChangeType(val, TypeCode.Int32);
Console.WriteLine("{0} converted to an Int32: {1}", val, num);
}
}输出结果
-3.456 converted to an Int32: -3
热门推荐
1 狗狗技能训练
5 如何训练狗狗笑
6 狗狗训练排便
9 狗狗响片训练
10 如何训练狗狗不捡食
11 狗狗尿训练
12 怎么训练狗狗找东西
13 狗狗训练站立
14 狗狗训练飞盘
15 鞍山狗狗训练
16 怎样训练泰迪狗狗谢谢
17 狗狗外出训练
18 怎么训练金毛狗狗大小便