Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# data structure to add elements in order

I am looking for a data structure in C# (.net framework) which I can use to add data in sorted order (instead of adding all data and then applying sort). My data are objects and I want to add them according to a certain field (integer field).

Thanks

like image 300
Saher Ahwal Avatar asked Feb 27 '26 12:02

Saher Ahwal


2 Answers

option 1) use the SortedList and use your integer fields as key.

option 2) use SortedSet but be cautious .. this collection can only contain unique objects (no duplicates of the same object)

like image 79
Yoeri Avatar answered Mar 01 '26 01:03

Yoeri


[System.Collections.Generic.SortedSet<T>][1]
like image 26
Av Pinzur Avatar answered Mar 01 '26 00:03

Av Pinzur



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!