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

Note that this is .Net 2.0, so LINQ is not an option.

Answer: 
Since the Sort method isn't on the IList interface you might consider creating your own:

```
interface ISortableList<T> : IList<T>
{
    void Sort();
    void Sort(IComparer<T> comparer);
}

class SortableList<T> : List<T>, ISortableList<T> { }

/* usage */
void Example(ISortedList<T> list)
{
    list.Sort();
    list.Sort(new MyCustomerComparer());
}

```

In general the parameter type you specify in your method should be the lowest common denominator of members you actually need to call. If you really need to call the Sort() method then your parameter should have that member defined. Otherwise you should probably load it into another object that can do what you want such as:

```
void Example(IList<T> list)
{
    list = new List<T>(list).Sort();
}

```

This should actually be pretty fast, almost certainly faster still than writing your own custom inline sort algorithm.
I know it isn't .NET 2.0 but I love LINQ so much and will endorse it every chance I get :)

**Simple Sort:**

```
var sortedProducts =
    from p in products
    orderby p.ProductName
    select p;

ObjectDumper.Write(sortedProducts);

```

**Sort by multiple conditions:**

```
string[] digits = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" };

var sortedDigits =
    from d in digits 
    orderby d.Length, d
    select d;

```

Both examples are from [101 Linq Samples](http://msdn.microsoft.com/en-us/vcsharp/aa336756.aspx)