C# int 与 string的相互转型

代码:

View Code
 1 class Program
2 {
3 static void Main()
4 {
5 int a = 123;
6 string s1 = a.ToString();
7 string s2 = Convert.ToString(a);
8 string s3 = ((IConvertible)a).ToString(null);
9
10 string s = "456";
11 int a1 = int.Parse(s);
12 int a2 = Convert.ToInt32(s);
13 int a3 = ((IConvertible)s).ToInt32(null);
14 int a4;
15 int.TryParse(s,out a4);
16 }
17 }

 

你可能感兴趣的:(C# int 与 string的相互转型)