閱讀331 返回首頁    go 阿裏雲 go 技術社區[雲棲]


Index was outside the bounds of the array.

背景今天寫了這麼一個函數:
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是否大於零

最後更新:2017-04-03 12:54:18

  上一篇:go Dev RadioGroup控件:實現單選效果
  下一篇:go Dataset中移除當前行,操作其它行