easy array question

  • Thread starter Thread starter jason
  • Start date Start date
J

jason

hello everyone,

i'm simply curious how to make an array out of some list of things (in
this case an SqlDataReader). essentially i want something like:

MyObject[] oObjectArray = null;

while (oReader.Read())
{
MyObject oObject = new MyObject();
oObject.Property1 = oReader["column1"];
oObject.Property2 = oReader["column2"];

// add logic to append this object to the end of the array here
}

one of two things occured to me. either there is a way to tell how many
records are waiting to be read in an SqlDataReader (which i have not
found to be the case), or there is a way to relatively easily
redimension an array (which the only examples i've seen so far involve
a lot of copying / moving data from old array to new array)

thanks for any help!

jason
 
Use an ArrayList rather than an array.

If you really, really need an array, ArrayList has a method to convert
it to an array after you've read everything.
 
Back
Top