IList ToArray Generic Extension Method – Summer of Nhibernate Session 6

Still working through session 6 of the Summer of Nhibernate and got to the bit where Steve is creating a criteria expression.  He’s converting an IList<int> to an array of ints using a ToArray method.
This conversion method doesn’t appear to be standard for IList and as I’m in a bit of a hurry today I’ve assumed it’s an extension method and wrote my own (code below) so I can follow the screen cast:

public static class MyExtensions
  public static T[] ToArray<T>(this IList<T> ListToConvert)
    T[] arrayToReturn = new T[ListToConvert.Count];
    for (int i = 0; i < arrayToReturn.Length; i++)  
      arrayToReturn[i] = ListToConvert[i];
    return arrayToReturn;

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s