Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

Enumerable.Concat: practical reference

Enumerable.Concat: practical reference: The deferred result yields every element of the first source and then every element of the second, retaining duplicates.

Version: .NET LINQ; verified on .NET 10.0.14

Syntax

source.Concat(/* overload-specific arguments */)

The deferred result yields every element of the first source and then every element of the second, retaining duplicates.

Use it to join sources sequentially when neither deduplication nor sorting is required.

The second source is not enumerated until the first completes. Failure or infinity in the first can prevent the second from being reached.

A null source throws ArgumentNullException when the query is created; source changes before enumeration may be visible.

The complete program actually uses Enumerable.Concat; its exact expected stdout is 1,2,3,4.

Examples

using System;
using System.Collections.Generic;
using System.Linq;

Console.WriteLine(string.Join(",", new[] { 1, 2 }.Concat(new[] { 3, 4 })));

Result

1,2,3,4

The complete program actually uses `Enumerable.Concat`; its exact expected stdout is `1,2,3,4`.

Sources