标签:bool 范围 main null click ace char console app
隐式类型转换
using System; namespace App{ class MyClass{ public static void Main(string[] args){ char a=‘A‘; int b=a; Console.WriteLine(b);//65 Console.WriteLine(a);//A } } }
显式类型转换
double a=10.902; int b=(int) a; Console.WriteLine(b);//10 Console.WriteLine(a);//10.902
要注意范围是否超出
string str = "56561515"; int b = System.Convert.ToInt32(str); Console.WriteLine(b);//10.902
using System; namespace App{ class MyClass{ public static void Main(string[] args){ //string str= Convert.ToString(null); bool str= Convert.ToString(null)==null;//True Console.WriteLine(str); } }
null转了之后还是null,""转了之后还是""。
bool str= Convert.ToString("")=="";//True Console.WriteLine(str);
标签:bool 范围 main null click ace char console app
原文地址:https://www.cnblogs.com/mlh1421/p/10699878.html