Linq ToList Operator - How to get a List from a sequence
LinqToListOperator.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 = { "Kokosboom", "Korean mango", "Litchi chinensis", "Mafai", "Knoeper", "Mangostin" };
Label1.Text = "Fruits List:....... <br />";
foreach (string item in fruits)
{
Label1.Text += item.ToString() + "<br />";
}
List<string> query = (from f in fruits
where f.StartsWith("K")
orderby f
select f).ToList();
Label2.Text = "Query Result Type: " + query.GetType() + "<br /><br />";
Label2.Text += "Query Result:.... <br />";
for (int i = 0; i < query.Count; i++)
{
Label2.Text += query[i].ToString() + "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq ToList Operator - How to get a List from a sequence</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
Linq Standard Query Operator: Conversion Operator - ToList
<br />How to get a List from a sequence
</h2>
<hr width="600" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="MidnightBlue"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="Crimson"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - ToList"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>

- linq - How to get last element of a sequence that match condition
- linq - Get a subset of elements from a sequence that match condition
- linq - How to concatenate two sequences
- 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
- linq - How to get difference between two sequences
- linq - How to get intersection of two sequences
- linq - How to union two sequences
- linq - How to create an XML declaration for a document
- linq - How to get the average value from a numeric sequence