The program is tested in the console program   , The following two methods are introduced , The code is as follows :
using System; namespace ConsoleApp17 { class Program { static void
Main(string[] args) { //double ➡ int //A method : Convert.Toint32(double) ➡ int : rounding
【 special ①】 //B method : (int)double ➡ Remove decimal double a = 3.4; double c = 3.6;
Console.WriteLine( Convert.ToInt32(a) +"\n"+ Convert.ToInt32(c) +"\n"+ (int)a
+"\n"+ (int)c +"\n" ); //【①】 If the decimal is in the middle of two integers , Then the integer is even , Not odd double b = 3.5;
double bb = 4.5; Console.WriteLine( Convert.ToInt32(b) + "\n" +
Convert.ToInt32(bb) + "\n" ); // If the parameter is Null,A Method correspondence 0,B Method error Console.WriteLine(
Convert.ToInt32(null) +"\n" //+ (int)null report errors ); //String ➡ int //A method :int
int.parse(String s); s If the format is not correct , Will report a mistake //B method : bool int.Tryparse(String s ,out int a);
If abnormal ,a=0, And return false String rightString = "2018"; String errorString = "liuyan";
Console.WriteLine( int.Parse(rightString) ); //int.Parse(errorString); report errors int
result3, result4; int.TryParse(rightString,out result3);
int.TryParse(errorString,out result4); Console.WriteLine(result3+"\n"+result4);
Console.Read(); } } }
Print as follows :

 

 

 

 

Technology