Step:2 Codes
Class : QueryExpression.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
/// <summary>
/// Summary description for QueryExpression
/// </summary>
public class QueryExpression
{
public int[] scores = new int[] { 99, 92, 93, 98,97,96,85 };
public QueryExpression()
{
//
// TODO: Add constructor logic here
//
}
}
Code Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs"
Inherits="_Default" %>
<!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.LINQQueryExpresion2</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text=" "></asp:Label>
</div>
</form>
</body>
</html>
Code Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
QueryExpression qs = new QueryExpression();
//Defining Query Expression from an Integer Array
IEnumerable<int> score_expression = from score in qs.scores where
score > 85 && score < 97 select score;
int highestscore = score_expression.Count();
int expression = (from score in qs.scores where score > 80 select
score).Count();
Label1.Text += "<br/> ";
foreach (int i in score_expression)
{
Label1.Text +="LINQ Expression : "+ i + ", ";
}
Label1.Text += "<br/> int highestscore : " + highestscore;
Label1.Text += "<br/> int expression : " + expression;
}
}