int.TtyParse(string s, out int i)

用来判断s字符串是否是由数字组成的,若是有数子组成,则将这个数字的值赋给i,同时这个式子返回bool类型的True。

若不是数字组成,则将i赋值为0,并且返回值为False。

  1. using System; 
  2. using System.Collections.Generic; 
  3. using System.Linq; 
  4. using System.Text; 
  5.  
  6. namespace 个人练习 
  7.     class Program 
  8.     { 
  9.         static void Main(string[] args) 
  10.         { 
  11.             string s01 = "alex"
  12.             string s02 = "1234"
  13.             int i01; 
  14.             int i02; 
  15.             bool b01 = int.TryParse(s01, out i01); 
  16.             Console.WriteLine(s01 + " " + b01 + " " + i01); 
  17.             bool b02 = int.TryParse(s02, out i02); 
  18.             Console.WriteLine(s02 + " " + b02 + " " + i02); 
  19.         } 
  20.     } 

int.TryParse(判断字符串是否为数字组成)_职场