-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Anand_2004
Message 1 in Discussion
Hi Folks , My previous article has one small error.In various places I have
mention form its a typo the correct word is from. In todays session I will
talk about Part B of LINQ . Here I am trying to demonstrate how efficient
and quickly we can play around with collection classes using LINQ .
using System;
using System.Collections.Generic;
using System.Text;
using System.Query;
using System.Xml.XLinq;
using System.Data.DLinq;
namespace QueryExpression
{
class Player
{
public string PlayerName;
public string Country;
public int TotalRuns;
public int NoManoftheMatch;
}
class Program
{
public List <Player> PlayerList = new List<Player>();
static void Main(string[] args)
{
Program pr = new Program();
pr.AddObj();
var queryOutput =
from player in pr.PlayerList
where ( player.TotalRuns>=10000)
orderby player.TotalRuns descending
select ( new {player.PlayerName,player.TotalRuns,player.NoManoftheMatch} );
foreach( var p in queryOutput)
{
Console.WriteLine("Name : {0} Runs : {1} Man of the Match (no of times) :
{2}",p.PlayerName,p.TotalRuns,p.NoManoftheMatch);
}
Console.ReadLine();
}
//adding the player information
public void AddObj()
{
Player objPlayer1 = new Player{PlayerName= "Sachin",Country="Ind",TotalRuns=
10527 ,NoManoftheMatch=10};
Player objPlayer2 = new Player{PlayerName= "Lara",Country="WI",TotalRuns=
11953,NoManoftheMatch=12};
Player objPlayer3 = new Player{PlayerName= "Ponting",Country="AUS",TotalRuns=
9316,NoManoftheMatch=14};
Player objPlayer4 = new Player{PlayerName= "Dravid",Country="Ind",TotalRuns=
9082,NoManoftheMatch=9};
Player objPlayer5 = new Player{PlayerName= "Inzi",Country="Pak",TotalRuns=
8615,NoManoftheMatch=8};
Player objPlayer6 = new Player{PlayerName= "Kallis",Country="SA",TotalRuns=
8072,NoManoftheMatch=16};
Player objPlayer7 = new Player{PlayerName= "Langer",Country="Aus",TotalRuns=
7623,NoManoftheMatch=8};
Player objPlayer8 = new Player{PlayerName= "SWaugh",Country="Aus",TotalRuns=
10527,NoManoftheMatch=14};
Player objPlayer9 = new Player{PlayerName= "Gavaskar",Country="Ind",TotalRuns=
10122,NoManoftheMatch=5};
Player objPlayer10 = new Player{PlayerName= "Border",Country="Aus",TotalRuns=
11174,NoManoftheMatch=11};
PlayerList.Add(objPlayer1);
PlayerList.Add(objPlayer2);
PlayerList.Add(objPlayer3);
PlayerList.Add(objPlayer4);
PlayerList.Add(objPlayer5);
PlayerList.Add(objPlayer6);
PlayerList.Add(objPlayer7);
PlayerList.Add(objPlayer8);
PlayerList.Add(objPlayer9);
PlayerList.Add(objPlayer10);
}
}
} If you look at the select or where this is nothing but the extension
methods defined in System.Query and new{
} is nothing anonymous type and
object initializer and in foreach loop I have used implicit typing of local
variables , without local variable type its very hard to get the required
output because we may not know the possible type of the data returned .
LINQ provides lots other options/clauses such as join, groupby, distinct,
union, any, all and aggregated functions ( sum, count, average, max, min,
aggregate) etc to support structure query language programming model more
strongly .I am concluding this session here and suggest you all top start
explore LINQ .If you have any doubt please feel free to post your queries to
me - [EMAIL PROTECTED] Cheers Anand https://anandkumar2004.wordpress.com
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member
Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you
received this message by mistake, please click the "Remove" link below. On the
pre-addressed e-mail message that opens, simply click "Send". Your e-mail
address will be deleted from this group's mailing list.
mailto:[EMAIL PROTECTED]