c#中的值类型转换

来源:百度知道 编辑:UC知道 时间:2024/09/25 05:38:23
如何把一给float的值转换为int类型的?最好是例子。。。答的好在追加分。

这么写就行了
private void button1_Click(object sender, EventArgs e)
{
float a = 10.4f;
int b = Convert.ToInt32(a);
}

这有3种方法~你看下
float a = 1f;
int b = int.Parse(a);
b = Convert.ToInt32(a);
b = (int)(a);