I have a list field shown below
List<int> myList = new List<int>(System.Linq.Enumerable.Range(0, 10));
I need to write code that inserts a new element (the integer 1) before every element in this list.
So the list should look like this
{1,0,1,1,1,2,1,3,1,...}
Any help?
2 replies to this topic
#1
Posted 23 September 2010 - 04:08 AM
|
|
|
#2
Posted 23 September 2010 - 11:50 PM
So the list is allready filled, or every time you add a thing to the list, it should first add '1' ?
#3
Posted 25 September 2010 - 01:51 PM
List<int> newList = new List<int>();
foreach (int i in myList) {
newList.Add(1); // That's a '1' (one) in there
newList.Add(i); // That's an 'i' (eye) in there
}
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









