【发布时间】:2013-05-23 10:37:48
【问题描述】:
我的代码显示未处理的 ArrayIndexOutOfRangeException 异常。
public static DateTime storeTime(String date)
{
string[] dateSplit;
string[] timeSplit;
DateTime returnValue = new DateTime();
if (date == "")
return returnValue;
dateSplit = date.Split(new Char[] { 'T' });
timeSplit = dateSplit[1].Split(new Char[] { '+' }); // Exception occurs here.
timeSplit[0] = timeSplit[0].Substring(0, timeSplit[0].Length - 1);
returnValue = DateTime.ParseExact(dateSplit[0] + " " + timeSplit[0], "yyyy-MM-dd HH:mm:ss",null);
return returnValue;
}
【问题讨论】:
-
听起来 dateSplit[1] 上没有元素...您将什么参数(日期)推入您的方法。请问您应该调试一下,dateSplit 中存储的内容,以解决您的问题...
-
你能粘贴
DateTime类吗? -
将 Rohit 的编辑从 [java] 更改为 [c#]...如果我这样做了,请纠正我。错了
标签: c# .net indexoutofboundsexception