首页 > 其他 > 详细

关于int.TryParse的使用

时间:2015-12-18 13:07:33      阅读:179      评论:0      收藏:0      [点我收藏+]

技术分享

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication7
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             string TP = "123abc";
14             string TPE = "123";
15             int re,ret;
16             //测试转换失败
17             if (int.TryParse(TP, out re) == true)
18             {
19                 Console.WriteLine("{0}能转换成功,转换后的数为:{1}",TP,re );
20             }
21             else
22             {
23                 Console.WriteLine("{0}转换失败",TP);
24             }
25             //暂停
26             Console.ReadKey();
27             Console.WriteLine();
28             //测试转换成功
29             if (int.TryParse(TPE, out ret) == true)
30             {
31                 Console.WriteLine("{0}能转换成功,转换后的数为:{1}" ,TPE,ret);
32             }
33             else
34             {
35                 Console.WriteLine("{0}转换失败",TPE);
36             }
37             //暂停
38             Console.ReadKey();
39         }
40     }
41 }

 

---恢复内容结束---

关于int.TryParse的使用

原文:http://www.cnblogs.com/start-from-scratch/p/5056675.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!