LINQ Query Expression
  • Ascending , Descending of Integers array datatypes.
  • Orderby clause for string array datatypes
  • AsEnumerable()
    var intArrayAscend = from n in intA.AsEnumerable() orderby n ascending select n;
    var intArrayDescend = from n in intA.AsEnumerable() orderby n descending select n;
  •  
Note, the flexibility of data handling. You can specify as string, integer or var.
  • foreach (String ThisValue in ThisQuery)
    {
    L1.Text += "&nbsp&nbsp" + ThisValue;
    }
  • foreach (int ThisValue in intA)
    {
    L1.Text += "&nbsp&nbsp" + ThisValue + ",";
    }
  • foreach (var ThisValue in intArrayDescend)
    {
    L1.Text += "&nbsp&nbsp" + ThisValue + ",";
    }

 

Step 1: Create New site

Step : 2 Edit Code

<%@ 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 id="Head1" runat="server">
<title>LINQ: Orderby Query</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div id="div1">
<asp:Label ID="L1" runat="server" ></asp:Label>
</div>
</form>
</body>
</html>
 

Step : 3 Code

using System;
using System.Data;
using System.Linq;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
String[] QueryString = { "One", "Two", "Three", "Four", "Five", "Six" };
int[] intA = { 1, 3, 2, 4, 5 };
// Define the query.
var ThisQuery =
from StringValue
in QueryString
orderby StringValue
orderby StringValue.Length
select StringValue + "\r\n";
//var intArrayAscend = from n in intA where n < 10 select n;
var intArrayAscend = from n in intA.AsEnumerable() orderby n ascending select n;
var intArrayDescend = from n in intA.AsEnumerable() orderby n descending select n;
// Display the String Data Type
L1.Text += "Read String : String Array Data Type <br/> &nbsp&nbsp&nbsp&nbsp";
foreach (String ThisValue in ThisQuery)
{
L1.Text += "&nbsp&nbsp" + ThisValue;
}
// Display the result.
L1.Text += "<br/>Read Integer: Integer Array Data Type <br/> &nbsp&nbsp";
// foreach (var ThisValue in intA)
foreach (int ThisValue in intA)
{
L1.Text += "&nbsp&nbsp" + ThisValue + ",";
}
L1.Text += "<br/>Read var and Sort Ascending: Integer Array Data Type <br/> &nbsp&nbsp";
// foreach (var ThisValue in intA)
foreach (var ThisValue in intArrayAscend)
{
L1.Text += "&nbsp&nbsp" + ThisValue + ",";
}
L1.Text += "<br/>Read var and Sort Descending: Integer Array Data Type <br/> &nbsp&nbsp";
// foreach (var ThisValue in intA)
foreach (var ThisValue in intArrayDescend)
{
L1.Text += "&nbsp&nbsp" + ThisValue + ",";
}

}
}



 

Step : 4 Runt time

 

Step : 5

Step : 6

Step : 7

Step : 8

Step : 9

Step : 10

Step : 11

Step : 12

Step : 13

Step : 14

Step : 15

Step : 16