I have a little dilemma I would like to straighten out.
I have a class Car with 100's of parameters.
I add a bunch of Car instances to a listbox. They are now plain old objects.
Then when I selected an item from the listbox, I would like to cast the object back to Car and print the parameters on screen.
so I have 2 options:
option 1:
option 2:
Option 1 Could be more efficient if the cast is pointing to the object, while option 2 creates a new object, which could be more efficient if a cast creates a new object each and every time. Which one is right, which one is wrong? A reference to the MSDN website would be nice
thanks a lot!
Matt
I have a class Car with 100's of parameters.
I add a bunch of Car instances to a listbox. They are now plain old objects.
Then when I selected an item from the listbox, I would like to cast the object back to Car and print the parameters on screen.
so I have 2 options:
option 1:
Code:
Textbox1.Text = ((Car) Listbox1.SelectedItem).param1.ToString(); Textbox2.Text = ((Car) Listbox1.SelectedItem).param2.ToString(); ... Textbox100.Text = ((Car) Listbox1.SelectedItem).param100.ToString();
Code:
Car c = new Car(); c = (Car) Listbox1.SelectedItem; Textbox1.Text = c.param1.ToString(); Textbox2.Text = c.param2.ToString(); ... Textbox100.Text = c.param100.ToString();
thanks a lot!
Matt
Comment