c# - Sorting a custom list by a property of the objects the list contains -


i have created custom list class not ienumerable. therefore, can't use enumerable.orderby.

class mylist<t>  {     class listelement     {         public t content;         public listelement next;     }     listelement head; } 

after put objects in have string property. want sort list string property of objects contains.

in case it's best use ienumerable, or better, derive list class... i'll show how can achieve both.

public class mylist<t> : ienumerable<t> {     private list<t> itemcollection;      public mylist()     {         this.itemcollection = null;     }      public void add(t item)     {         this.itemcollection.add(item);     }       public ienumerator<t> getenumerator()     {         foreach (t item in this.itemcollection)         {             yield return item;         }     }      /// <summary>     /// returns enumerator iterates through collection.     /// </summary>     /// <returns>     /// <see cref="t:system.collections.ienumerator"/> object can used iterate through collection.     /// </returns>     ienumerator ienumerable.getenumerator()     {         return this.getenumerator();     } } 

or easiest of all...

public class mylist<t> : list<t> {  } 

Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -