Linq Any Operator - How to determine if any items in a sequence meet a condition
LinqAnyOperator.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
string[] fruits = { "Albicocco", "Brotfruchtbaum", "Chicozapote", "Coffea arabica", "Guanabana", "Lansibaum" };
Boolean isAnyStratWithL = (from f in fruits
select f).Any(f => f.StartsWith("L"));
Boolean isAnyStratWithZ = (from f in fruits
select f).Any(f => f.StartsWith("Z"));
Label1.Text = "Fruits List: <br />";
foreach (string names in fruits)
{
Label1.Text += names.ToString() + "<br />";
}
Label2.Text = "After Calling Any Operator [StartsWith('L')]: " + isAnyStratWithL.ToString();
Label2.Text += "<br /><br />After Calling Any Operator [StartsWith('Z')]: " + isAnyStratWithZ.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq Any Operator - How to determine if any items in a sequence meet a condition</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
Linq Standard Query Operator: Quantifier Operator - Any
<br />How to determine if any items in a sequence meet a condition
</h2>
<hr width="585" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="DarkGreen"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="Red"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - Any"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
- linq - How to count items of a sequence
- linq - How to get maximum value of a numeric sequence
- linq - How to sort elements of a sequence in ascending order
- How to use linq select query
- linq - How to determine if a sequence contains a specific element
- linq - How to get a sequence without duplicate items
- linq - How to reverse the order of elements in a sequence
- linq - Get a subset of sequence that skips unmatched condition items
- linq - How to get element at a specified index in a sequence
- linq - How to get the first element of a sequence