CSharp - Concatenation without Using the Concat Operator

Description

Concatenation without Using the Concat Operator

Demo

using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
class Program//from  www . j  ava2 s  .co m
{
    static void Main(string[] args)
    {
        string[] codeNames = {"Python", "Java", "Javascript", "Bash", "C++", "Oracle"};
        
        IEnumerable<string> items = new[] {
                                      codeNames.Take(5),
                                      codeNames.Skip(5)
                                    }
                                    .SelectMany(s => s);
        
        foreach (string item in items)
                Console.WriteLine(item);
    }
}

Result

In the following example we created an array consisting of two sequences:

  • one created by calling the Take operator on the input sequence and
  • another created by calling the Skip operator on the input sequence.

Then we are calling the SelectMany operator on the array of sequences.

Concat operator allows only two sequences to be concatenated together, this technique allows an array of sequences.

Related Topic