Projection Anonymous Query with Where restriction

Step : 1 Create new web site ( http://manas6/aspnet.35/mm.LINQQueryProjection2/ )

Step : Edit code

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" Debug="true"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>mm.LINQQueryProjection2:</title>
</head>
<body>
<form id="form1" runat="server">
<div>
Filtering Anonymous Query with where Restriction: <br />
<asp:Label ID="L1" runat="server" Text=""> </asp:Label>
<br />
<asp:Label ID="L2" runat="server" Text=""> </asp:Label>

</div>
</form>
</body>
</html>
 

Default.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Collections;
public partial class _Default : System.Web.UI.Page
{
protected int[] numbers = {0, 1,2,3,4,5,6};
protected string[] days = { "Sun", "Mon", "Tue", "Wed", "Thurs", "Fri","Sat" };
protected void Page_Load(object sender, EventArgs e)
{
L1.Text += "--Select Projection with int array --<br/>";
if (!IsPostBack)
{
var numerals =
from n in numbers where n <5
select (n+1) ;
L1.Text += "Days in a week ";
foreach (var s in numerals)
{
L1.Text += s + "&nbsp";
}
}
L2.Text += "--Select Projection with Anonymous Type --<br/>";
if (!IsPostBack)
{
int n1 = 1;
var numdays = from n in numbers where n < 5
select new {day = days[n]};

foreach (var s in numdays)
{
L2.Text +="day " + n1 +" is " + s.day + "<br/> " ;
n1++;
}
}
}
}

 

Step : 3 Run time analysis

Step :