首页 > 其他 > 详细

L#中 int.TryParse 有问题

时间:2016-01-15 12:30:54      阅读:132      评论:0      收藏:0      [点我收藏+]

今天发现了一个 L# 的异常。。因此记录一下

 

 1 List<string> strList = new List<string>();
 2 for(int i=0; i<4; ++i)
 3 {
 4     for(int j=0; j<4; ++j)
 5     {
 6         strList.Add(string.Format("{0}{1}", i, j));
 7     }
 8 }
 9 
10 int row = 0, col = 0;
11 for(int i=0; i<strList.Count; ++i)
12 {
13     int.TryParse(strList[i][0].ToString(), out row);
14     int.TryParse(strList[i][1].ToString(), out col);
15     Debug.LogFormat("({0}, {1})", row, col);
16     Debug.Log(row < 4 && col < 4);
17 }

 

 

上面这段代码的输出结果:

技术分享

 

如果把后面的循环内改成 int.Parse 就不会出错

1 for(int i=0; i<strList.Count; ++i)
2 {
3     row = int.Parse(strList[i][0].ToString());
4     col = int.Parse(strList[i][1].ToString());
5     Debug.LogFormat("({0}, {1})", row, col);
6     Debug.Log(row < 4 && col < 4);
7 }

 

L#中 int.TryParse 有问题

原文:http://www.cnblogs.com/gabo/p/5132840.html

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