int.TtyParse(string s, out int i)
用来判断s字符串是否是由数字组成的,若是有数子组成,则将这个数字的值赋给i,同时这个式子返回bool类型的True。
若不是数字组成,则将i赋值为0,并且返回值为False。
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace 个人练习
- {
- class Program
- {
- static void Main(string[] args)
- {
- string s01 = "alex";
- string s02 = "1234";
- int i01;
- int i02;
- bool b01 = int.TryParse(s01, out i01);
- Console.WriteLine(s01 + " " + b01 + " " + i01);
- bool b02 = int.TryParse(s02, out i02);
- Console.WriteLine(s02 + " " + b02 + " " + i02);
- }
- }
- }