您当前的位置: 首页 >  ar

衣舞晨风

暂无认证

  • 0浏览

    0关注

    1156博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Index was outside the bounds of the array.

衣舞晨风 发布时间:2014-01-08 09:44:39 ,浏览量:0

背景今天写了这么一个函数:
private string DateFormatConversion(string str)
        {
                string year = "";
                char[] pstr = str.ToCharArray();
                for (int k = 0; k < 4; k++)
                {
                    year += pstr[k];
                }
                return year;
        }
当str传入值如空的时候,就会提示“Index was outside the bounds of the array.”错误。
解决方案:
在处理str之前,先判断str.Length是否大于零
关注
打赏
1647422595
查看更多评论
立即登录/注册

微信扫码登录

0.0412s