Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>From the blog of Paul Fox, I recommend the post "How to sort an IList": <a href="http://foxsys.blogspot.com/2007/06/how-to-sort-generic-ilist.html" rel="nofollow noreferrer">http://foxsys.blogspot.com/2007/06/how-to-sort-generic-ilist.html</a></p> <p>Just in case that blog goes away in the future, I'll copy the post here:</p> <hr> <p><strong>How to sort a generic IList</strong></p> <p>Update</p> <p>You can read and updated post about <a href="http://foxsys.blogspot.com/2008/05/how-to-sort-generic-list-sorting-list.html" rel="nofollow noreferrer">sorting generic IList and List</a>. Many people will prefer the methods mentioned in the updated post.</p> <p>Sorting a generic IList</p> <p>I was trying to sort a generic IList&lt;> and found a fairly simple way of doing it.</p> <p>Step 1</p> <p>You need to implement IComparable for the type contained in your IList. For this example I am going to use a simple Language Dto class.</p> <pre><code>public class LanguageDto : IComparable { private String name; public string Name { get { return name; } set { name = value; } } public LanguageDto(string name) { this.name = name; } #region IComparable Members public int CompareTo(object obj) { if (obj is LanguageDto) { LanguageDto language = (LanguageDto)obj; return this.name.CompareTo(language.name); } throw new ArgumentException(string.Format("Cannot compare a LanguageDto to an {0}", obj.GetType().ToString())); } #endregion } </code></pre> <p>STEP 2</p> <p>Sort your IList. To do this you will use the ArrayList.Adapter() method passing in your IList, and then calling the Sort method. Like so...</p> <pre><code>ArrayList.Adapter((IList)languages).Sort(); </code></pre> <p>Note: languages is of type "IList"</p> <p>Languages should then be a sorted list of your type!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload