c# - Creating instances of classes at runtime -
- i have created class (conflictingbooking) contains fields various information in regards specific reservation.
- i loop through database , select reservations based on criteria.
- i want create instance of class selected criteria.
- 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
Post a Comment