Ich habe eine Arraylist mit Objekten, jetzt muss ich sie sortieren.C# dynamisch Attribut zum Sortieren auswählen
Ich habe diese Methode bekam:
public Int32 CompareTo(object next)
{
SessionInfo nextCase = (SessionInfo)next;
return (this.Duration.CompareTo(nextCase.Duration));
}
Jetzt muss ich dynamicly die sortvalue ändern von „Dauer“ auf „Name“ Also machte ich ein Attribut namens SortColumn und gab es Wert „Dauer“
Jetzt sieht mein Code wie folgt aus:
public string SortColumn { get; set; }
public SessionInfo()
{
SortColumn = "Duration";
}
public Int32 CompareTo(object next)
{
SessionInfo nextCase = (SessionInfo)next;
return (this.SortColumn.CompareTo(nextCase.SortColumn));
}
Das funktioniert nicht. Gibt es eine Möglichkeit, die zu sortierende Spalte zu ändern?
Danke!