Linq TakeWhile Operator - How to get a sequence that takes items that meet an expression
LinqTakeWhileOperator.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[] nums = { 129,56,21,9,421,169,26,89 };
IEnumerable<int> val = nums.OrderBy(n => n).TakeWhile(n=> n<50);
Label1.Text = "Numbers List: <br />";
foreach (int i in nums)
{
Label1.Text += i.ToString() + "<br />";
}
Label2.Text = "After Calling TakeWhile(number<50) Operator:<br />";
foreach (int n in val)
{
Label2.Text += n.ToString() + "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq TakeWhile Operator - How to get a sequence that takes items that meet an expression</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
Linq Standard Query Operator: Partitioning Operator - TakeWhile
<br />How to get a sequence that takes items that meet an expression
</h2>
<hr width="650" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="OrangeRed"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="SaddleBrown"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - TakeWhile"
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 determine if all items in a sequence match condition
- linq - How to concatenate two sequences
- 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 create an XML document
- linq - How to create an XML element
- linq - How to count occurrences of a string within a string