首页 新闻 搜索 专区 学院

关于string.Join() 方法中字符串长度的判断

0
[已解决问题] 解决于 2016-01-21 19:12
if ((jointLength < 0) || ((jointLength + 1) < 0) ) {
                throw new OutOfMemoryException();
            }
 
 //If this is an empty string, just return.
 if (jointLength == 0) {
       return String.Empty;
 }
第一个If中 or 后面的判断
 ((jointLength + 1) < 0) 
有什么意义呢,难道前面的判断范围不包括后面的吗?
jhkmnm的主页 jhkmnm | 初学一级 | 园豆:19
提问于:2014-04-17 11:59
< >
分享
最佳答案
0

http://referencesource.microsoft.com/#mscorlib/system/string.cs

看看注释吧

//Note that we may not catch all overflows with this check (since we could have wrapped around the 4gb range any number of times and landed back in the positive range.) The input array might be modifed from other threads, so we have to do an overflow check before each append below anyway. Those overflows will get caught down there.
奖励园豆:5
李永京 | 老鸟四级 |园豆:3114 | 2014-04-17 14:27

有解释一下不?

jhkmnm | 园豆:19 (初学一级) | 2014-04-17 15:43
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册