Linq ToArray Operator - How to get an Array from a sequence
LinqToArrayOperator.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 = { "Flor de Jamaica", "Fraise", "Fruit du dragon", "Grape", "Gulupa", "Kathon" };
Label1.Text = "Fruits List:....... <br />";
foreach (string item in fruits)
{
Label1.Text += item.ToString() + "<br />";
}
string[] query = (from f in fruits
where f.StartsWith("F")
orderby f
select f).ToArray();
Label2.Text = "Query Result: Items Count - " + query.Length.ToString() + "<br />";
for (int i = 0; i < query.Length; i++)
{
Label2.Text += query[i].ToString() + "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq ToArray Operator - How to get an Array 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 - ToArray
<br />How to get an Array 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="DarkMagenta"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - ToArray"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>

- linq - How to get difference between two sequences
- linq - How to get intersection of two sequences
- linq - How to filter elements of a sequence by data type
- c# - How to convert Linq query result to a List
- linq - How to union two sequences
- linq - How to create a comment in an XML document
- linq - How to create an XML document
- linq - How to select distinct elements from a sequence
- LINQ to remove objects within a List
- linq - How to sort a date list order by ascending descending