C# Winform | List Sort | ObservableCollection Sort
List Sort
Code - 1
List<ClassObject> orgList = new List<ClassObject>();
List<ClassObject> tempList = orgList.OrderBy(x => x.FiledName).ToList();
|
cs |
Code - 2
List<classObject> orgList = new List<classObject>();
orgList.Sort(delegate (classObjectx, classObjecty)
{
if (x.FiledName == null && y.FiledName == null) return 0;
else if (x.FiledName == null) return -1;
else if (y.FiledName == null) return 1;
else return x.FiledName.CompareTo(y.FiledName);
});
|
cs |
ObservableCollection Sort
ObservableCollection<classObject> orgObservableCollection = new ObservableCollection<classObject>();
var tempObservableCollection = orgObservableCollection.OrderByDescending(o => o.FiledName).ToList();
foreach (var temp in tempObservableCollection)
{
int oldIndex = orgObservableCollection.IndexOf(temp);
int newIndex = tempObservableCollection.IndexOf(temp);
orgObservableCollection.Move(oldIndex, newIndex);
}
|
cs |
2번째 라인의 정렬방식
var tempObservableCollection = orgObservableCollection.OrderByDescending(o => o.FiledName).ToList();
- OrderBy : 오름차순
- OrderByDescending : 내림차순
'C# Winform' 카테고리의 다른 글
C# Winform | Parse, Convert - System.FormatException (0) | 2020.08.31 |
---|---|
C# Winform | Json - Read, Write (0) | 2020.08.24 |
C# Winform | enum foreach (0) | 2020.05.06 |
C# Winform | Hardware Info | CPU ID, HDD, Mac, Serial (0) | 2020.04.29 |
C# Winform | DateTime Convert(Long To, TimeStamp to) (0) | 2020.04.28 |