18 1 月, 2008

[ZT]如何把string解析为int?

Q:如何把string解析为int?
A:简单的方法有三种:
string source = “1412”;
int result = 0;
// 使用Convert.ToInt32(string value);
result = Convert.ToInt32(source);
// 使用Int32.Parse(string value);
result = Int32.Parse(source);
// 使用Int32.TryParse(string s, out int result);
Int32.TryParse(source, out result);

Continue reading…