Add item to list

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

Is it possible to add an item to the start of a List<Product>?

Basically I have an existing list and I want to add an item to become
the first item of the list.

Thanks,
Miguel
 
Sure...just look at the Insert() method.

Note that if your list is large and you expect to be doing this often, you  
may want a different data structure.

Pete

Thank You Peter.

I opted for another option. I create an empty list A where I add the
first item then I concat list A with list B to create the final list.

I suppose this is ok.

Thanks,
Miguel
 
I opted for another option. I create an empty list A where I add the
first item then I concat list A with list B to create the final list.

Sometimes it is necessary to insert a new item at a specific location
in a list. The Insert() method is provided for this specific purpose.
Insert() takes two arguments, an integer indicating the index location
of the insertion and the item to be inserted at that location.

You u need to create one more list object that going to be used only
to add at the first item at front where u have something called insert
().....


~thanks
Vijay
http://www.s7software.com
 
Back
Top