Linq Cast Operator - How to cast elements in a sequence to a given type
LinqCastOperator.aspx
<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.Linq" %>
<!DOCTYPE html>
<script runat="server">
protected void Button1_Click(object sender, System.EventArgs e)
{
ArrayList fruits = new ArrayList();
fruits.Add("Afrikanische Malve");
fruits.Add("Aprikosenbaum");
fruits.Add("Averrhoa carambola");
fruits.Add("Cerasus avium");
fruits.Add("Date palm");
Label1.Text = "ArrayList (fruits):....... <br />";
foreach (string item in fruits)
{
Label1.Text += item.ToString() + "<br />";
}
IEnumerable<string> query = fruits.Cast<string>().Select(f => f);
Label2.Text = "Query Result:....... <br />";
foreach (string item in query)
{
Label2.Text += item.ToString() + "<br />";
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Linq Cast Operator - How to cast elements in a sequence to a given type</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h2 style="color:DarkBlue; font-style:italic;">
Linq Standard Query Operator: Conversion Operator - Cast
<br />How to cast elements in a sequence to a given type
</h2>
<hr width="575" align="left" color="CornFlowerBlue" />
<asp:Label
ID="Label1"
runat="server"
Font-Size="X-Large"
ForeColor="MediumSeaGreen"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Label
ID="Label2"
runat="server"
Font-Size="X-Large"
ForeColor="Purple"
Font-Italic="true"
>
</asp:Label>
<br />
<asp:Button
ID="Button1"
runat="server"
OnClick="Button1_Click"
Text="Test Linq Query Operator - Cast"
Height="45"
Font-Bold="true"
ForeColor="DodgerBlue"
/>
</div>
</form>
</body>
</html>
- linq - How to determine if all items in a sequence match condition
- linq - How to determine if any items in a sequence match condition
- linq - How to determine if a sequence contains a specific element
- linq - Get first element of a sequence that match condition
- linq - How to get first element of a sequence or a default value
- 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 - Get single element of a sequence that match condition or a default value