If there any short way besides foreach loop and new collection creation to add object after specific object in existing List ?
Just an example:
"amy","jerry","tony","amy","jack". I want to add "simon" after each "amy" in short way
You can use Linq to do this.
Uses a foreach but you can put it into a extension method to keep the code clear.
You can easily put this into a extension method.
Now the call:
If you know where you want to enter an item, you can do
Have a look here: http://msdn.microsoft.com/en-us/library/sey5k5z4.aspx
You have to use the Insert(int index, T item) in a List for adding the element into the List at the specified index. If index is equal to Count, item is added to the end of List. This method is an O(n) operation, where n is Count.