<p>I have an <code>IList&lt;T&gt;</code> that I need to sort, and I would rather not copy the list if possible.  I've noticed that <code>ArrayList</code> has an <code>Adapter</code> static method that wraps the passed list without copying it, but this takes an <code>IList</code> and I have an <code>IList&lt;T&gt;</code>.  Is it safe to cast from a <code>System.Collections.Generic.IList&lt;T&gt;</code> to a <code>System.Collections.IList</code> and just use the <code>Adapter</code> method?</p>

<p>Note that this is .Net 2.0, so LINQ is not an option.</p>

From the blog of Paul Fox, I recommend the post "How to sort an IList":
http://foxsys.blogspot.com/2007/06/how-to-sort-generic-ilist.html
Just in case that blog goes away in the future, I'll copy the post here:
How to sort a generic IList
Update
You can read and updated post about
sorting generic IList and List
. Many people will prefer the methods mentioned in the updated post.
Sorting a generic IList
I was trying to sort a generic IList<> and found a fairly simple way of doing it.
Step 1
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.
```
```
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
}
```
```
STEP 2
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...
```
```
ArrayList.Adapter((IList)languages).Sort();
```
```
Note: languages is of type "IList"
Languages should then be a sorted list of your type!