help me please! I have a list:

List<string[]> Data = new List<string[]> { new string[] {"nol", "odin", "dva", "tri", " four"}, new string[] {"nol", "odin", "dva", "tri", " four"}, new string[] {"nol", "odin", "dva", "tri", " four"} }; 

and an array of indexes that need to be removed. It can be of different lengths.

 int[] removesindex = {1, 3, 4}; 

that is, I want to get such a list

 List<string[]> newData = new List<string[]> { new string[] {"nol", "dva"}, new string[] {"nol", "dva"}, new string[] {"nol", "dva"} }; 

I can get the opposite indexes that should be left

    1 answer 1

     for (int i = 0; i < Data.Count; ++i) Data[i] = Data[i].Where((x, idx) => !removesindex.Contains(idx)).ToArray(); 

    Well or so, if it is permissible to create another list:

     Data = Data.Select(a => a.Where((x, idx) => !removesindex.Contains(idx)).ToArray()).ToList(); 
    • Hospadi how much time I spent trying to come up with this (((, I did not know that through lumbda the second parameter means the index, thanks a lot! - Tim
    • there is one minus if I need to remove 0 will be removed and the element with the index 10, 20, etc. @ Andrey - Tim
    • Uh, where did you get it? Can I counterexample? - Andrey NOP
    • I apologize, I was wrong - everything works as it should - Tim