Linq All Operator - How to determine if all items in a sequence meet a condition
LinqAllOperator.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 = { "Abricotier", "Abrikoos", "Actinidia", "Aguacate", "Alupag", "Anguria" };
Boolean isStratWithA = (from f in fruits
select f).All(f => f.StartsWith("A"));
Boolean isStratWithB = (from f in fruits
select f).All(f => f.StartsWith("B"));
Label1.Text = "Fruits List: <br />";
foreach (string names in fruits)
{
Label1.Text += names.ToString() + "<br />";
}
Label2.Text = "After Calling All Operator [StartsWith('A')]: " + isStratWithA.ToString();
Label2.Text += "<br /><br />After Calling All Operator [StartsWith('B')]: " + isStratWithB.ToString();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq All Operator - How to determine if all 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 - All
<br />How to determine if all items in a sequence meet a condition
</h2>
<hr width="575" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="Crimson"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="RoyalBlue"
Font-Italic="true"
>
</asp:Label>
<br /><br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - All"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>

- linq - How to sort elements of a sequence in ascending order
- How to use linq select query
- linq - How to get the sum of items in a numeric sequence
- linq - How to get element at a specified index in a sequence
- linq - How to get the first element of a sequence
- linq - How to return a default value if query result is empty
- linq - How to get element at a specified index or a default value
- linq - How to get intersection of two sequences
- linq - How to filter elements of a sequence by data type
- How to convert Linq query result to an array