LinQ
LinQ is tightly coupled to C# and VB
Imperative Programming language: Programmers want to describe the statement(C# and VB)
Declartive Programming language : In the case of SQL,the engine determines the physical strategy to retrive the logical request made in the form of a query.
Most mordern language supports RDBMS in their code,like Xml .But nothing was type safe.Microsoft solution is LinQ ,a type safe query.
Note : LinQ can be coded in Lambda syntax(Anonymous code blocks from functional programming Community ) and comprehension syntax.
Lambda Syntax : Normally takes => as expression.
How linq makes development Easy
Example 1 : without using LinQ
void NameContainsA()
{
List cell = new List ();
string[] Names = new string[]{
"Anish"
,"Varghese"
,"Linq"
,"Anish Varghese"};
for(int iCount=0; iCount<>
{
if(Names [iCount].StartsWith("A"))
{
cell.Add(Names[i]);
}
}
Example 2 : With LinQ
void NameContainsA()
{
List cell = new List ();
string[] Names = new string[]{
"Anish"
,"Varghese"
,"Linq"
,"Anish Varghese"};
cell = (from n in Names where n.StartsWith("A") select n).ToList();
}
Note : this makes the development very easy.
Example 3 : With Linq (above same example with less number of codes)
void NameContainsA()
{
List cell = new List ();
string[] Names = new string[]{
"Anish"
,"Varghese"
,"Linq"
,"Anish Varghese"};
cell = Names.Where(x => x.StartsWith("A")).ToList();
}
0 comments:
Post a Comment