how to sort list of object? OrderBy c# -


i have track class

class track {     public string name { get; set; }     public double duration;     public boolean isremix;      public override string tostring()     {         if (isremix) return name + "(remix) " + duration;         return name + " " + duration;     } } 

and album list:

class album :list<track>     {         public album sortbyalphabet()         {             return new album().orderby(x=>x.name);         }     } 

how can order album track's name? in sortbyalphabet need album output.

edit

return this.orderby(x=>x.name).tolist(); 

and

return (album)this.orderby(x=>x.name).tolist(); 

doesn't

it's
throwing exception, invalidcastexception

i not suggest inheriting list, if do, following should meet requirement:

class album : list<track> {     public album() : base() { }      public album(ienumerable<track> tracks) : base(tracks) { }      /// <summary>     /// sort in place album of tracks alphabetically name      /// </summary>     public void sortbyalphabet()     {         sort((t1, t2) => t1.name.compareto(t2.name));     }      /// <summary>     /// return new album tracks sorted alphabetically name.     /// </summary>     /// <returns></returns>     public album orderbyalphabet()     {         return new album(this.orderby(t => t.name));     } }