Jump to content

LINQ list

- - - - -

  • Please log in to reply
2 replies to this topic

#1
aakinn

aakinn

    Newbie

  • Members
  • PipPip
  • 24 posts
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
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
So the list is allready filled, or every time you add a thing to the list, it should first add '1' ?

#3
Momerath

Momerath

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 242 posts
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