首页 > 代码库 > 【你吐吧c#每日学习】11.10 C# Data Type conversion

【你吐吧c#每日学习】11.10 C# Data Type conversion

implicit

explicit

float f=12123456.213F

 

int a = Convert.ToInt32(f); //throw exception or

int a = (int)f; // not throw exception nut got an overflow value

 

parse and tryparse

string to other datatype

string a="100fh";

int num=int.Parse(a); //throw exception

int result=0;

bool isNum=int.TryParse(num,out result);

if(isNum){ Console.WriteLine(result);

}else{

Console.WriteLine("Invalid")}

【你吐吧c#每日学习】11.10 C# Data Type conversion