转换为string类型:
//第一种
string s = num.ToString();
//第二种
string s = Convert.ToString(num);
转换为int类型:
//第一种
int num= Convert.ToInt32(str);
//第二种
int num = 0;
int.TryParse(str, out num);
转换为decimal类型:
decimal dec=Convert.ToDecimal(str);
转换为DateTime类型:
string repTime="2020/1/1";
DateTime time = Convert.ToDateTime(repTime);//调整日期格式为string.ToString("yyyy-MM-dd")
本文详细介绍了在C#中如何进行数据类型的转换,包括将数值类型转换为字符串,字符串转换为整数,数值转换为小数,以及日期时间转换等操作。

3万+

被折叠的 条评论
为什么被折叠?



