Simple LINQ :
- MSDN : "A query is a set of instructions that describes what
data to retrieve from a given data source (or sources) andwhat
shape and organization the returned data should have. A query is
distinct from the results that it produces."
- LINQ Querying a string and serializing an array
- Query Expression : MSDN " A query expression is a
query expressed in query syntax. A query expression is a
first-class language construct. It is just like any other
expression and can be used in any context in which a C#
expression is valid. A query expression consists of a set of
clauses written in a declarative syntax similar to SQL or XQuery.
Each clause in turn contains one or more C# expressions, and
these expressions may themselves be either a query expression or
contain a query expression."
- A query expression must begin with a from clause and must
end with a select or group clause.
- Between the first from clause and the last select or group
clause, it can contain one or more of these optional clauses:
where, orderby , join , let and even additional from clauses.
- You can also use the into keyword to enable the result of a
join or group clause to serve as the source for additional query
clauses in the same query expression.
Major Standard Query Operators
|
Family |
Operators |
| Filetering |
ofType, Where |
| Projection |
Select, Selectmany |
| Partioning |
Skip, SkipWhile, Take, TakeWhile |
| Concatenation |
Concat |
| Ordering |
OrderBy , Then , Reverse |
| Grouping |
GroupBy |
| Set |
Distinct, Except, Intersect, Union |
| Conversion |
AsNumerable, AsQQuerablem Cast, ToArray, ToDictionary,
ToList |
| Equality |
SequenceEqual |
| Element |
ElementAt, ElementAtorDefault, First, FirstorDefault,
Lastm LastOrDefault, Single, SingleOrDefault |
| Generation |
DefaultIfEmpty, Empty, Range, Repeat |
| Quantifiers |
All, Any, Contains |
| Aggregation |
Aggregate, Average, Count, Max,Min, Sum |
|
Codes : 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.LINQSimple1: from : where : select clauses</title>
<link href="main.css" rel="stylesheet" type="text/css" />
</head>
<body >
<form id="form1" runat="server">
<div id="div1"> This is an example of Serializing an Array String <br
/>
<asp:Label ID="L1" runat="server" ></asp:Label>
</div>
</form>
</body>
</html>
Code Default.aspx.cs
using System;
using System.Linq;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string[] words = { "March", "April", "May", "June", "January",
"February", "October", "December" };
// LINQ Query for short words and long words
var shortWords = from word in words where
word.Length <= 5 select word;
var LongWords = from word in words where word.Length >= 5 select
word;
// Print each word out with foreach loop/ LINQ query
L1.Text += "  Short Words : <br/>";
foreach (var word in shortWords)
{
L1.Text += "  : " + word.ToString();
}
L1.Text += " <hr> Long Words <br/>" ;
foreach (var word in LongWords)
{
//Console.WriteLine(word);
L1.Text += "  : " + word.ToString();
}
}
}
Runt time : in the first query the words those are less than 5 will
be filtered, and in the next loop those words are equal or more than
5 character in length will be filtered,

|