c# - Creating instances of classes at runtime -


  1. i have created class (conflictingbooking) contains fields various information in regards specific reservation.
  2. i loop through database , select reservations based on criteria.
  3. i want create instance of class selected criteria.
  4. i want add each of class instances list use elsewhere.

problem have @ step 3. want name new instance "found[i]" incremented each reservation found:

              conflictingbooking found = new conflictingbooking();               found.bookingnumber = conflictingbookingnumber;               found.bookingstarts = conflictingbookingdt;                conflictingbookings.add(found); 

in above code, need replace 'found' programatically.

whilst appreciate simple code snippet follow, read reference know i'm doing :-). don't know how google problem.

seems have not been entirely clear - here appropriate code:

      dbmanager.open();       dbmanager.executereader(commandtype.text, string.format("select bookingdate, {0} btable court in {1} , bookingdate in ({2})", columns, facilityids, bookingdates));       using (idatareader rdr = dbmanager.datareader)       {         decimal conflictingbookingnumber = 0;         datetime conflictingbookingdt;         object result = null;         while (rdr.read())         {           (int = 0; < requestedcolumnnames.count; i++)           {             result = dbmanager.datareader[requestedcolumnnames[i].tostring()];             if (result != null)               conflictingbookingnumber = convert.todecimal(result);              result = dbmanager.datareader["bookingdate"];             if (result != null)               conflictingbookingdt = convert.todatetime(result);              if (conflictingbookingnumber > 0)             {               int next = conflictingbookings.count + 1;                 conflictingbooking found = new conflictingbooking();               found.bookingnumber = conflictingbookingnumber;               found.bookingstarts = conflictingbookingdt;                // conflictingbookings list<conflictingbooking>               conflictingbookings.add(found);             }           }         }       } 

hope clarifies problem.

i think looking put code in loop. might misunderstanding seems if want this

int = 0; foreach(var result in resultset) {      conflictingbooking found = new conflictingbooking();     found.bookingnumber = conflictingbookingnumber;     found.bookingstarts = conflictingbookingdt;     found.name = "found["+i++ +"]";      conflictingbookings.add(found); } 

if that's not want please clarify question


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -