LINQ A Journey through Operators [Concat]

LINQ A Journey through Operators [Concat]

  • Comments 2

 

Imagine you have two arrays and you need to join them. Using LINQ it is as simple as mentioned

 

using System;

using System.Collections.Generic;

using System.Text;

using System.Query;

using System.Xml.XLinq;

using System.Data.DLinq;

 

namespace LINQ_Concat

{

    class Program

    {

        static void Main(string[] args)

        {

 

            char[] alpha1 = {'A','B','C','D','E','F','G','H','I'};

            char[] alpha2 = {'J','K','L','M','N','O','P','Q','R'};

 

            var alphaAll = alpha1.Concat(alpha2);

 

            foreach(var al in alphaAll)

            {

                Console.WriteLine(al);

            }

            Console.ReadKey();

        }

    }

}

 

Output will look like

 

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

 

Namoskar

 

Leave a Comment
  • Please add 1 and 1 and type the answer here:
  • Post
  • Is Concat usable as a static method as well? I would rather write Concat(alpha1, alpha2). I know that the extension methods are defined as static methods, but are they also usable as such or will C# enforce the above syntax?

  • What is cool... is that you can order at the same time...

    If your letters were jumbled, you could write

    var alphaAll = alpha1.Concat(alpha2).OrderBy(a => a);

    And you'd sort and concat them at the same time!!!

Page 1 of 1 (2 items)