Queryable.Union Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Produces the set union of two sequences.
Overloads
| Name | Description |
|---|---|
|
Union |
Produces the set union of two sequences by using the default equality comparer. |
|
Union |
Produces the set union of two sequences by using a specified IEqualityComparer |
Union(IQueryable, IEnumerable)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Produces the set union of two sequences by using the default equality comparer.
public:
generic
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable ^ Union(System::Linq::IQueryable ^ source1, System::Collections::Generic::IEnumerable ^ source2);
public static System.Linq.IQueryable Union(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IQueryable Union(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2);
static member Union : System.Linq.IQueryable<'Source> * seq<'Source> -> System.Linq.IQueryable<'Source>
[]
static member Union : System.Linq.IQueryable<'Source> * seq<'Source> -> System.Linq.IQueryable<'Source>
Public Function Union(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource)) As IQueryable(Of TSource)
Type Parameters
- TSource
The type of the elements of the input sequences.
Parameters
- source1
-
IQueryable
A sequence whose distinct elements form the first set for the union operation.
- source2
-
IEnumerable
A sequence whose distinct elements form the second set for the union operation.
Returns
An IQueryable
- Attributes
Exceptions
source1 or source2 is null.
Examples
The following code example demonstrates how to use Union
int[] ints1 = { 5, 3, 9, 7, 5, 9, 3, 7 };
int[] ints2 = { 8, 3, 6, 4, 4, 9, 1, 0 };
// Get the set union of the items in the two arrays.
IEnumerable union = ints1.AsQueryable().Union(ints2);
foreach (int num in union)
Console.Write("{0} ", num);
/*
This code produces the following output:
5 3 9 7 8 6 4 1 0
*/
Dim ints1() As Integer = {5, 3, 9, 7, 5, 9, 3, 7}
Dim ints2() As Integer = {8, 3, 6, 4, 4, 9, 1, 0}
' Get the set union of the items in the two arrays.
Dim union = ints1.AsQueryable().Union(ints2)
Dim output As New System.Text.StringBuilder
For Each num As Integer In union
output.Append(String.Format("{0} ", num))
Next
' Display the output.
MsgBox(output.ToString())
' This code produces the following output:
' 5 3 9 7 8 6 4 1 0
Remarks
The Unionsource1 parameter.
The query behavior that occurs as a result of executing an expression tree that represents calling Unionsource1 parameter. The expected behavior is that the set union of the elements in source1 and source2 is returned.
Applies to
Union(IQueryable, IEnumerable, IEqualityComparer)
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
- Source:
- Queryable.cs
Produces the set union of two sequences by using a specified IEqualityComparer
public:
generic
[System::Runtime::CompilerServices::Extension]
static System::Linq::IQueryable ^ Union(System::Linq::IQueryable ^ source1, System::Collections::Generic::IEnumerable ^ source2, System::Collections::Generic::IEqualityComparer ^ comparer);
public static System.Linq.IQueryable Union(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2, System.Collections.Generic.IEqualityComparer comparer);
public static System.Linq.IQueryable Union(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2, System.Collections.Generic.IEqualityComparer? comparer);
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Enumerating collections as IQueryable can require creating new generic types or methods, which requires creating code at runtime. This may not work when AOT compiling.")]
public static System.Linq.IQueryable Union(this System.Linq.IQueryable source1, System.Collections.Generic.IEnumerable source2, System.Collections.Generic.IEqualityComparer? comparer);
static member Union : System.Linq.IQueryable<'Source> * seq<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> System.Linq.IQueryable<'Source>
[]
static member Union : System.Linq.IQueryable<'Source> * seq<'Source> * System.Collections.Generic.IEqualityComparer<'Source> -> System.Linq.IQueryable<'Source>
Public Function Union(Of TSource) (source1 As IQueryable(Of TSource), source2 As IEnumerable(Of TSource), comparer As IEqualityComparer(Of TSource)) As IQueryable(Of TSource)
Type Parameters
- TSource
The type of the elements of the input sequences.
Parameters
- source1
-
IQueryable
A sequence whose distinct elements form the first set for the union operation.
- source2
-
IEnumerable
A sequence whose distinct elements form the second set for the union operation.
- comparer
-
IEqualityComparer
An IEqualityComparer
Returns
An IQueryable
- Attributes
Exceptions
source1 or source2 is null.
Remarks
The Unionsource1 parameter.
The query behavior that occurs as a result of executing an expression tree that represents calling Unionsource1 parameter. The expected behavior is that the set union of the elements in source1 and source2 is returned. The comparer parameter is used to compare values.