CSharp - Use Take, Skip, Concat, and SequenceEqual operators to compare sequences


We get the first five elements of the original input sequence by calling the Take operator.

Then concatenate on the input sequence starting with the sixth element using the Skip and Concat operators.

Finally, we determine whether that concatenated sequence is equal to the original sequence calling the SequenceEqual operator.


using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program/* w  w w .  j a v a2s. co m*/
    static void Main(string[] args)
        string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};
        bool eq = codeNames.SequenceEqual(codeNames.Take(5).Concat(codeNames.Skip(5)));


Related Topic