Eine nicht behandelte Ausnahme des Typs 'System.ArgumentOutOfRangeException' ist in mscorlib.dll
In den folgenden code, bekam ich folgenden Fehler.
Eine nicht behandelte Ausnahme des Typs 'System.ArgumentOutOfRangeException' ist in mscorlib.dll
Zusätzliche Informationen: der Index war außerhalb des Bereichs. Muss nicht negativ und kleiner als die Größe der Sammlung.
Hier ist der code:
public ProcessInformation GetMaxRunTimeForApplicationsBetween(DateTime StartingTime, DateTime EndingTime)
{
//Filter Based on Timer
List<ProcessInformation> filterList = new List<ProcessInformation>();
foreach (HarvestApp.ProcessInformation item in this.ProcessList)
{
if (item.started_at.CompareTo(StartingTime) >= 0 && item.ended_at.CompareTo(EndingTime) <= 0)
{
filterList.Add(item);
}
}
//Count Max Occurrence of Application
List<int> countApplicationList = new List<int>();
List<string> applicationNameList = new List<string>();
foreach (HarvestApp.ProcessInformation item in filterList)
{
if (applicationNameList.Contains(item.name))
{
countApplicationList[applicationNameList.IndexOf(item.name)]++;
}
else
{
applicationNameList.Add(item.name);
countApplicationList.Add(1);
}
}
//if (countApplicationList.Count == 0)
//{
// throw new InvalidOperationException("Empty list");
//}
int max = int.MinValue;
foreach (int item in countApplicationList)
{
if (item > max)
{
max = item;
}
}
//Return corresponding ProcessInformation Class of applicationNameList
return filterList[filterList.FindIndex(delegate
(ProcessInformation proc)
{
return proc.name.Equals(applicationNameList[countApplicationList.IndexOf(max)], StringComparison.Ordinal);
})];
}
Raten C#, die von der exception-name und der code-Stil, aber wenn nicht, bitte re-tag mit einer entsprechenden language-tag.
Diese Ausnahme kann auftreten, in einem Anzahl Plätze in diesem code. Welche Linie ist es Versagen? Wissen Sie, dass viel.
Ausnahme Auftritt bei der return-Anweisung.
Was ist der stacktrace?
Diese Ausnahme kann auftreten, in einem Anzahl Plätze in diesem code. Welche Linie ist es Versagen? Wissen Sie, dass viel.
Ausnahme Auftritt bei der return-Anweisung.
Was ist der stacktrace?
InformationsquelleAutor user2413158 | 2013-06-10
Du musst angemeldet sein, um einen Kommentar abzugeben.
Ich denke, Fehler Zeile ist hier:
Weil
List<T>.FindIndex
zurückkehren können-1
wenn Sie nicht finden können, index.Stattdessen sollten Sie testen, ob der index kleiner als 0 zeigt an, dass ein Fehler aufgetreten ist, bevor Sie es verwenden:
InformationsquelleAutor 윤진수
Hier ist das problem:
Sollte es so sein
Das ist nicht die Quelle der aktuellen Fehler.
InformationsquelleAutor Venu Vedula