Append list at a specific spot.

  • Thread starter Thread starter 4D1 (thEsp)
  • Start date Start date
4

4D1 (thEsp)

Guest
Hello,

How do I add an item to list at a specific location (row), while at the same time moving other items below?

For example (this is unmodified list): 1,2,4,5. And I want to insert 3 to third spot ONLY, the result should look like this: 1,2,3,4,5.

I made a function which is supposed to do that, but I had a problem, I couldn't compile the program because of a error telling me this 'List' is a 'variable' but is used like a 'method'

public static List<object> AppendList(List<object> List,int Row,object Value)
{
List<object> NewList = new List<object>();
for (int iRow = 0; iRow < List.Count + 1; iRow++)
{
if(iRow == Row)
{
NewList.Add(Value);
continue;
}
NewList.Add(List(iRow));
}

return (List<object>) (NewList);
}

Continue reading...
 
Back
Top