Excluding one item from list (by Index), and take all others

Ajay picture Ajay · Dec 31, 2014 · Viewed 18.1k times · Source

There is a List<int> containing some set of numbers. Randomly I select an index, which will be processed separately (call it master). Now, I want to exclude this particular index, and get all other elements of List (call them slave).

var items = new List<int> { 55, 66, 77, 88, 99 };
int MasterIndex = new Random().Next(0, items .Count);

var master = items.Skip(MasterIndex).First();

// How to get the other items into another List<int> now? 
/*  -- items.Join;
    -- items.Select;
    -- items.Except */

Join, Select, Except - any of them, and how?

EDIT: Cannot remove any item from the original list, otherwise I have to keep two lists.

Answer

Rahul Singh picture Rahul Singh · Dec 31, 2014

Use Where:-

var result = numbers.Where((v, i) => i != MasterIndex).ToList();

Working Fiddle.