Given the integer sequence A. Get a new sequence. If the sequence number of the element A is divided by 3 completely, then this element is not included in the new sequence; if the remainder of dividing the sequence number by 3 is 1, then the double value of this element is added to the new sequence; otherwise, the item is added to the new sequence unchanged.

How not to include items divisible by 3? What ways are there?

  • @ Alex9, According to the rules of the forum, questions should not be limited to the decision or the completion of student assignments. Please clarify what you have done yourself and what did not work out. - DreamChild
  • I did everything, except not including the elements with numbers dividing totally into 3. - Vladimir Smirnov

1 answer 1

Use the Where overload, which, in addition to the element, provides the element index:

 var list = new List<string>() { "one", "two", "three", "four" } var newList = list.Where((s, i) => i % 3 != 0); // two, three 

newList will contain elements whose indices are not divided into three.