Linq Union Operator - How to get a sequence representing the union of two sequences
LinqUnionOperator.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
int[] nums1 = { 1, 2, 2, 3, 4, 5, 6, 7, 7, 8, 9, 10 };
int[] nums2 = { 1, 3, 3, 5, 7, 9, 11 };
Label1.Text = "Number List 1:....... <br />";
foreach (int n in nums1)
{
Label1.Text += n.ToString() + ", ";
}
Label1.Text += "<br /><br />Number List 2:....... <br />";
foreach (int n in nums2)
{
Label1.Text += n.ToString() + ", ";
}
var val = nums1.Union(nums2);
Label2.Text = "<br />After Call Union Operator [nums1.Union(nums2)]:....... <br />";
foreach (int n in val)
{
Label2.Text += n.ToString() + ", ";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq Union Operator - How to get a sequence representing the union of two sequences</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
Linq Standard Query Operator: Set Operator - Union
<br />How to get a sequence representing the union of two sequences
</h2>
<hr width="625" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="SeaGreen"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="DarkMagenta"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - Union"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
- linq - How to count items of a sequence
- linq - How to sort elements of a sequence in ascending order
- How to use linq select query
- linq - Get first element of a sequence that match condition
- linq - How to get first element of a sequence or a default value
- linq - How to get single element of a sequence that match condition
- linq - How to get single element of a sequence or a default value
- c# - How to convert Linq query result to a List
- linq - How to create an XML declaration for a document
- linq - How to get the average value from a numeric sequence