Linq Intersect Operator - How to get a sequence representing the intersection of two sequences
LinqIntersectOperator.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, 3, 4, 5, 6, 7, 7, 8, 9, 9, 10 };
int[] nums2 = { 1, 3, 3, 5, 7, 9, 9, 11 };
Label1.Text = "Number List 1 (nums1):....... <br />";
foreach (int n in nums1)
{
Label1.Text += n.ToString() + ", ";
}
Label1.Text += "<br /><br />Number List 2 (nums2):....... <br />";
foreach (int n in nums2)
{
Label1.Text += n.ToString() + ", ";
}
var val = nums1.Intersect(nums2);
Label2.Text = "<br />After Call Intersect Operator [nums1.Intersect(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 Intersect Operator - How to get a sequence representing the intersection 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 - Intersect
<br />How to get a sequence representing the intersection of two sequences
</h2>
<hr width="675" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="MediumOrchid"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="Purple"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - Intersect"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
- linq - How to get single element of a sequence that match condition
- linq - How to get difference between two sequences
- linq - How to filter elements of a sequence by data type
- How to convert Linq query result to an array
- c# - How to convert Linq query result to a List
- linq - How to get the average value from a numeric sequence
- linq - How to create a comment in an XML document
- linq - How to count occurrences of a string within a string
- linq - How to select distinct elements from a sequence
- linq - How to sort a date list order by ascending descending