我在运行时遇到了这个错误。 如果你能解释这对我的编码有很大的帮助。谢谢。我的代码错误“System.IndexOutOfRangeException”
public int timePeriodInSeconds(String timeInFormat)
{
System.Diagnostics.Debug.WriteLine("timePeriodInSeconds timeInFormat= " + timeInFormat);
String[] timeFactors = timeInFormat.Split(':');
System.Diagnostics.Debug.WriteLine("timePeriodInSeconds timeFactors[0]" + timeFactors[0]);
System.Diagnostics.Debug.WriteLine("timePeriodInSeconds timeFactors[1]" + timeFactors[1]);
System.Diagnostics.Debug.WriteLine("timePeriodInSeconds timeFactors[2]" + timeFactors[2]);
int hours = Convert.ToInt32(timeFactors[0]);
int minutes = Convert.ToInt32(timeFactors[1]);
int seconds = Convert.ToInt32(timeFactors[2]);
System.Diagnostics.Debug.WriteLine("timePeriodInSeconds hours" + hours);
System.Diagnostics.Debug.WriteLine("timePeriodInSeconds minutes" + minutes);
System.Diagnostics.Debug.WriteLine("timePeriodInSeconds seconds" + seconds);
return (hours * 60 * 60 + minutes * 60 + seconds);
}
'timeFactors'只有1个位置,并且您试图访问第二个(超出边界)。只是调试你的代码 – Petaflop
谢谢先生。我对这种语言很陌生。这个编码部分是由我的朋友完成的。现在我想开发这个。所以这个错误发生了,你可以进一步解释。 – SNP
如果您不熟悉该语言,我建议您购买一些书并开始使用。在这个特殊情况下,这应该有助于你理解发生了什么:http://csharp.net-tutorials.com/basics/arrays/ – Petaflop