tag:blogger.com,1999:blog-67584665667766862722024-03-05T20:48:30.486-08:00LINQ Study MaterialFor LINQ class room training send me mail at malhotra.isha3388@gmail.comAnonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.comBlogger13125tag:blogger.com,1999:blog-6758466566776686272.post-88006680615681797072013-10-29T11:40:00.007-07:002013-10-29T11:40:49.442-07:00LINQ to Stored Procedure(without parameter)<div dir="ltr" style="text-align: left;" trbidi="on">
<div class="MsoNormal">
<span style="font-size: large;"><span style="line-height: 27px;">For Advance Asp.net Training Fill <a href="http://techaltum.com/Contact.aspx" target="_blank">Enquiry Form</a></span></span></div>
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span style="font-size: 28.0pt; line-height: 115%;">LINQ to Stored
Procedure<o:p></o:p></span></u></b></div>
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span style="font-size: 28.0pt; line-height: 115%;">(Without Parameter)<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">LINQ also
provide facility to connect with <a href="http://techaltum-sqlserver.blogspot.in/2013/03/stored-procedure-in-sql-server.html" target="_blank">Stored Procedure</a>. Following is the table which
I am using to explain this topic.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Table
Name:-Emp<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_12" o:spid="_x0000_i1030" style="height: 58.5pt; mso-wrap-style: square; visibility: visible; width: 100.5pt;" type="#_x0000_t75">
<v:imagedata o:title="sp_linq-1" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq1FFeEEpaw5tuUT3G4hxVz5ooGQsMxuAfJO41ofXo3DCEeVmX_gC9Bw72zzwUdGPhiMQpkTdohcqmosP1xUupaWa2hD27TEB9jQLQABhrILFYQJpjYf0WZOsEphHCA19nM-LehEfXxck/s1600/sp_linq-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="232" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiq1FFeEEpaw5tuUT3G4hxVz5ooGQsMxuAfJO41ofXo3DCEeVmX_gC9Bw72zzwUdGPhiMQpkTdohcqmosP1xUupaWa2hD27TEB9jQLQABhrILFYQJpjYf0WZOsEphHCA19nM-LehEfXxck/s400/sp_linq-1.png" width="400" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 1<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">To work with
LINQ to SQL we have to add LINQ Classes. Using Add New Item add <a href="http://isha-linq.blogspot.in/2013/04/linq-hour-2-linq-to-sql.html" target="_blank">LINQ to SQL</a>
Classes. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="_x0000_i1029" style="height: 258.75pt; mso-wrap-style: square; visibility: visible; width: 451.5pt;" type="#_x0000_t75">
<v:imagedata o:title="sp_linq-2" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTdw-BsLyxSQR7xvimcnf8-MC5gRp1WVzWYstOIcD5TBD649r2BQSY8UQCKbjAsskPWEdMdTI0vx3zvpFp9PvTb_iwC5N3T8Wa4joY4B2VFKxa1aoxoJE9L58Hsu3kuC4WrnHrQXo58e4/s1600/sp_linq-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiTdw-BsLyxSQR7xvimcnf8-MC5gRp1WVzWYstOIcD5TBD649r2BQSY8UQCKbjAsskPWEdMdTI0vx3zvpFp9PvTb_iwC5N3T8Wa4joY4B2VFKxa1aoxoJE9L58Hsu3kuC4WrnHrQXo58e4/s640/sp_linq-2.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 2<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Now create
class to map with Table Emp<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Data.Linq.Mapping;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Table</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">(Name=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Emp"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">//IsDbGenerated
represents that it is Identity column</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> [</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Column</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">(IsPrimaryKey=</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">true</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, IsDbGenerated=</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">true</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> id;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> [</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Column</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> name;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> [</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Column</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> age;<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">}</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Follow the
following steps:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Step 1:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Create
Stored Procedure <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">create</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">proc</span> <span style="color: teal;">selectAllData</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">as</span><span style="font-family: Consolas; font-size: 14.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">select</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: grey;">*</span> <span style="color: blue;">from</span> <span style="color: teal;">emp<o:p></o:p></span></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Step 2:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">To work with
stored procedure in LINQ we have to use DataContext class. To run stored
procedure we have to use </span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">ExecuteMethodCall</span><span style="font-size: 14.0pt; line-height: 115%;"> which is protected type. So we have
to first inherit the DataContext Class to call the method </span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">ExecuteMethodCall</span><span style="font-size: 14.0pt; line-height: 115%;"> ().<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"></span></div>
<a name='more'></a><br /><br />
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">I have created
the class name DAO and inherit the DataContext class in it.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">(Kindly add
the namespace System.Data.LINQ)<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Initialize
the DataContext class constructor and pass connection string to it.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">DAO</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">DataContext</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> DAO(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> con_string)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> : </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">base</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">(con_string)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> { }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">}</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Step 3:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Now create the method in the DAO class to work with
Stored Procedure<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Function</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">(Name = </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"selectAllData"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
IsComposable = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">false</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">ISingleResult</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> EmpData()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">ISingleResult</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res = (</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">ISingleResult</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">>)((ExecuteMethodCall(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">this</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, (</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">MethodInfo</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">)(</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">MethodInfo</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">.GetCurrentMethod()))).ReturnValue);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Assign the function attribute on the method which is in <span style="background: white; mso-highlight: white;">System.Data.Linq.Mapping</span>
namespace. Function attribute is used for Stored Procedure and User Defined
Function.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Name property define the stored procedure name and
IsComposable=false is used for stored procedure and IsComposable=true is used
for user defined function.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">The complete code is as follows:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Data.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Data.Linq.Mapping;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Reflection;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Data;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">DAO</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">:</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">DataContext</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> DAO(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">string</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> con_string)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> : </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">base</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">(con_string)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> { }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> [</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Function</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">(Name = </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"selectAllData"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, IsComposable = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">false</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">ISingleResult</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> EmpData()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">ISingleResult</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res = (</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">ISingleResult</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">>)((ExecuteMethodCall(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">this</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, (</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">MethodInfo</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">)(</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">MethodInfo</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">.GetCurrentMethod()))).ReturnValue);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">return</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">}</span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Now create
the object of DAO class and call the method EmpData()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">using</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">public</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">partial</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">class</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">LinqToSP</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> : System.Web.UI.</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">Page</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">protected</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">void</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Page_Load(</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">object</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> sender, </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">EventArgs</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">DAO</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> d = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">DAO</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Data
Source=ISHA;Initial Catalog=isha;Persist Security Info=True;User
ID=isha;Password=pass@123"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> d.EmpData())<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(data.id + </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">" "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> +
data.name+</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">}</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">The output of this code is as follow:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_13" o:spid="_x0000_i1028" style="height: 85.5pt; mso-wrap-style: square; visibility: visible; width: 234pt;" type="#_x0000_t75">
<v:imagedata o:title="" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtyFll_e4TRNk2KqQRt-Hbv6u739g_-OeP6MoXML5JFcNAy_t5Y63zKi_TA8mVxEmJbRzTp6jnDxq8I52ciiY9OWWWj4-6QjT1Cha0E3iE1eF0RjGwH94JhanaQNwbFZbzHKZ459ktu2w/s1600/sp_linq-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="146" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgtyFll_e4TRNk2KqQRt-Hbv6u739g_-OeP6MoXML5JFcNAy_t5Y63zKi_TA8mVxEmJbRzTp6jnDxq8I52ciiY9OWWWj4-6QjT1Cha0E3iE1eF0RjGwH94JhanaQNwbFZbzHKZ459ktu2w/s400/sp_linq-3.png" width="400" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 3<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com13tag:blogger.com,1999:blog-6758466566776686272.post-22819414263101739962013-10-07T01:09:00.001-07:002013-10-07T01:09:58.386-07:00Set Operations in LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span style="font-size: 36.0pt; line-height: 115%;">Set Operations in
LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">We use
following set operations in LINQ:-<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 24.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 24.0pt; line-height: 115%;">Distinct<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Distinct
remove redundancy and show the unique records. <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="_x0000_i1035" style="height: 177.75pt; mso-wrap-style: square; visibility: visible; width: 249pt;" type="#_x0000_t75">
<v:imagedata o:title="set-1" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJG1oqcWazWJPSI_jpfPfRF5FFI2b-yCX8ZX4a-tiUaSDDPArA6h2RmXgV0da0Co8buZAlLDbV87hrMJYrtS2atoRu7yHhXB5kqLRcpadda9zXC-ayT1TKsrbfgXkFKBeBsAvPOi5jJ3k/s1600/set-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="297" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgJG1oqcWazWJPSI_jpfPfRF5FFI2b-yCX8ZX4a-tiUaSDDPArA6h2RmXgV0da0Co8buZAlLDbV87hrMJYrtS2atoRu7yHhXB5kqLRcpadda9zXC-ayT1TKsrbfgXkFKBeBsAvPOi5jJ3k/s320/set-1.png" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 1<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] techaltum = { 1, 2, 3, 4, 3, 4, 5, 19, 89, 4, 8, 2 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">IEnumerable</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res = techaltum.Distinct();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Result after Distinct <br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(data+</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<a name='more'></a><br />
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Output of this code is as follows:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_5" o:spid="_x0000_i1034" style="height: 111pt; mso-wrap-style: square; visibility: visible; width: 250.5pt;" type="#_x0000_t75">
<v:imagedata o:title="set-2" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRFIFPEIHtsAyYpoevFIjCbkSNcf6MC2uaxx4gjryzyPhf9JQD6CoL12-YlSIo4lGop_vSZW9LQfANrFYgN4bfd5jZVvDBAIHPTTfHKl4BWZy7PMiSUzQ9BHSkn08ZOCAdDPigVHKFpfE/s1600/set-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="219" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiRFIFPEIHtsAyYpoevFIjCbkSNcf6MC2uaxx4gjryzyPhf9JQD6CoL12-YlSIo4lGop_vSZW9LQfANrFYgN4bfd5jZVvDBAIHPTTfHKl4BWZy7PMiSUzQ9BHSkn08ZOCAdDPigVHKFpfE/s320/set-2.png" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 2<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 26.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 26.0pt; line-height: 115%;">Except<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Except operator
returns those values from first data source which do not repeated in second
data source.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_6" o:spid="_x0000_i1033" style="height: 304.5pt; mso-wrap-style: square; visibility: visible; width: 250.5pt;" type="#_x0000_t75">
<v:imagedata o:title="set-3" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIE4eNHaWFQlGkybPC9N0EXHBOFeGBvHDZQnecBqY-fnHEdALLCQRQ2wE_f4WIqap3JMJyGZPPZXONDGwqbvpj2YtdJ31S2mym7wGguqj39ccLzLCf9ZQJp3iVm767rxdKcm0su2GgHkw/s1600/set-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiIE4eNHaWFQlGkybPC9N0EXHBOFeGBvHDZQnecBqY-fnHEdALLCQRQ2wE_f4WIqap3JMJyGZPPZXONDGwqbvpj2YtdJ31S2mym7wGguqj39ccLzLCf9ZQJp3iVm767rxdKcm0su2GgHkw/s320/set-3.png" width="263" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 3<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] techaltum1 = { 1, 2, 3, 4, 3, 4, 5, 19 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] techaltum2 = { 100, 200, 300, 2, 14, 90, 1, 3 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">IEnumerable</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res = techaltum1.Except(techaltum2);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Result after Except <br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(data+</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Output of this code as follows:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_7" o:spid="_x0000_i1032" style="height: 94.5pt; mso-wrap-style: square; visibility: visible; width: 253.5pt;" type="#_x0000_t75">
<v:imagedata o:title="set-4" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSiv1pzfN5ooJOOtCUsuP2aBBvqlGfvbKa-7839fUq4blPtLUzOBu5imJ9loWUsubf-k-XNzkE6yaFATNI486mmVNpGy8HwcqwtIGQAb6bguzurdvnzdmMA1dLdN4i10PdmQ4_WDCkRD8/s1600/set-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="119" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiSiv1pzfN5ooJOOtCUsuP2aBBvqlGfvbKa-7839fUq4blPtLUzOBu5imJ9loWUsubf-k-XNzkE6yaFATNI486mmVNpGy8HwcqwtIGQAb6bguzurdvnzdmMA1dLdN4i10PdmQ4_WDCkRD8/s320/set-4.png" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 4<o:p></o:p></span></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></b></div>
<div class="MsoNormal">
<b><span style="font-size: 14.0pt; line-height: 115%;">Note: - except will not return those
value which not in first data source but in second data source.<o:p></o:p></span></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 36.0pt; line-height: 115%;">Intersect<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Intersect returns
those values which are common in both data Source.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_8" o:spid="_x0000_i1031" style="height: 304.5pt; mso-wrap-style: square; visibility: visible; width: 250.5pt;" type="#_x0000_t75">
<v:imagedata o:title="set-5" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7pzqu-uUm2UC9iTUfAkk340g-mHLEdq6vrtsVLxkK7VWKvY5E5D0FSXDD6imtnLenMDYTDyWPm-buYt_TnOVERVBnX2UrKhnKM1YKCwGhYs-6duA_KYKu21CHRvLuZUxHRLZfkIuy9lE/s1600/set-5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh7pzqu-uUm2UC9iTUfAkk340g-mHLEdq6vrtsVLxkK7VWKvY5E5D0FSXDD6imtnLenMDYTDyWPm-buYt_TnOVERVBnX2UrKhnKM1YKCwGhYs-6duA_KYKu21CHRvLuZUxHRLZfkIuy9lE/s320/set-5.png" width="263" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 5<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] techaltum1 = { 1, 2, 3, 4, 3, 4, 5, 19,100 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] techaltum2 = { 100, 200, 300, 2, 14, 90, 1, 3 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">IEnumerable</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res = techaltum1.Intersect(techaltum2);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Result after Intersect <br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(data+</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Output of this code:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_9" o:spid="_x0000_i1030" style="height: 110.25pt; mso-wrap-style: square; visibility: visible; width: 247.5pt;" type="#_x0000_t75">
<v:imagedata o:title="set-6" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image006.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBtHv2WBTY1tADS18vP2xq_2AQ1ZAUMtSexZxbZCs0UlFPaBxyCl6JpNQ5i6rI_yfC7O3P0LKF-8Q0VIik7PE9vQGQFJc-CtOcL-Zr7bsXVZOh-8DozUXN2ldDky3IYJFR7mKHS5D8YHM/s1600/set-6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="142" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgBtHv2WBTY1tADS18vP2xq_2AQ1ZAUMtSexZxbZCs0UlFPaBxyCl6JpNQ5i6rI_yfC7O3P0LKF-8Q0VIik7PE9vQGQFJc-CtOcL-Zr7bsXVZOh-8DozUXN2ldDky3IYJFR7mKHS5D8YHM/s320/set-6.png" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 6<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 28.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 28.0pt; line-height: 115%;">Union<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">It will show
the sequence value of two data source.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">First it
will show values of first data source and then second data source but it shows
repeated value only one time.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_10" o:spid="_x0000_i1029" style="height: 304.5pt; mso-wrap-style: square; visibility: visible; width: 250.5pt;" type="#_x0000_t75">
<v:imagedata o:title="set-7" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image007.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR3hxXFRdPsWtYb_HKPL2keJ3l_eRGHeFcTF_j1KIZBl8s8EadGpObMPSuzZCaXW5hos4HFC0zkt9T7JjaQFkSzf0ITyvNVtjd7LfMwdWQ1ftRtGgL4MmsmAtq4qJVEKmKeQq9nsWKAj8/s1600/set-7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="320" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhR3hxXFRdPsWtYb_HKPL2keJ3l_eRGHeFcTF_j1KIZBl8s8EadGpObMPSuzZCaXW5hos4HFC0zkt9T7JjaQFkSzf0ITyvNVtjd7LfMwdWQ1ftRtGgL4MmsmAtq4qJVEKmKeQq9nsWKAj8/s320/set-7.png" width="263" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 7<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] techaltum1 = { 1, 3, 4 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] techaltum2 = { 2, 200,3, 300,14 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">IEnumerable</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res = techaltum1.Union(techaltum2);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Result after Union <br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(data+</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">The output of this code as follows:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><v:shape id="Picture_x0020_11" o:spid="_x0000_i1028" style="height: 153pt; mso-wrap-style: square; visibility: visible; width: 255pt;" type="#_x0000_t75">
<v:imagedata o:title="Set-8" src="file:///C:\Users\Isha\AppData\Local\Temp\msohtmlclip1\01\clip_image008.png">
</v:imagedata></v:shape></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjveOwUBGbs2i2QoNoZ-thb_NvOKMXUxQknlXyBTtwIOjr-v_1ZPYGvtzIdC6LtKIlgVl5dgXr4CCyI1Or2Sy654kVDGyEfqXxQtRrh142tJcAYDLL0X1g8cg9cDgMYE-FxPPsumsL2B0U/s1600/Set-8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="192" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjveOwUBGbs2i2QoNoZ-thb_NvOKMXUxQknlXyBTtwIOjr-v_1ZPYGvtzIdC6LtKIlgVl5dgXr4CCyI1Or2Sy654kVDGyEfqXxQtRrh142tJcAYDLL0X1g8cg9cDgMYE-FxPPsumsL2B0U/s320/Set-8.png" width="320" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 8<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Hope you
enjoyed the article<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com4tag:blogger.com,1999:blog-6758466566776686272.post-43583326542252083342013-08-18T12:19:00.000-07:002013-08-18T12:19:01.041-07:00First and Last Method in LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Written By:-<a href="https://www.facebook.com/isha.malhotra3388" target="_blank">Isha Malhotra</a> </span></span><br />
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Our Website:-<a href="http://www.techaltum.com/" target="_blank">www.techaltum.com</a> </span></span><br />
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;"><br /></span></span>
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span style="font-size: 26.0pt; line-height: 115%;">First and Last in
LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 22.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 22.0pt; line-height: 115%;">Use of First in LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">First method
in LINQ just select the top 1 value from the data source.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">First with array<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 45, 56, 89, 56, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> first = marks.First();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">"First Element "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> + first);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Ouput<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs2iIZH_UVFMESs5v7uiAVB4_jUb5EeVPfin-9jb69LQ6oF0n3nATpsxwxW-tzPV__ZWHufnPSgT6NELFNIenK5OrRPd62pnbeFUrMy2eIQYBcrfHXEFwqGa57kToi8zPi_2bwv8mKAA0/s1600/f-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="160" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjs2iIZH_UVFMESs5v7uiAVB4_jUb5EeVPfin-9jb69LQ6oF0n3nATpsxwxW-tzPV__ZWHufnPSgT6NELFNIenK5OrRPd62pnbeFUrMy2eIQYBcrfHXEFwqGa57kToi8zPi_2bwv8mKAA0/s640/f-1.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">We can also
pass condition while calling first method<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"></span></u></b></div>
<a name='more'></a><b><u><br /></u></b><br />
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 45, 56, 89, 56, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> first = marks.First(x=>x%2==0);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">"First Element "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> + first);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">It will simply show 78.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Similarly we can implement the same code on class type
list.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">For
example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Note:-data
is class which contains variable roll_no, student and per.<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> dt = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=1, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"isha"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=2, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"rahul"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=2, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"rahul"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=5, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"renu"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=5, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"sapna"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=89}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res = dt.First();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Roll No:- "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> +
res.roll_no + </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">" Student:- "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> + res.student + </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">" per:- "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
+ res.per + </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">And
if you want to put any condition then you can add your condition which is as
follows:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res = dt.First(x=>x.per>90);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> </span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 22pt; line-height: 115%;">Use
of Last in LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Last method
in LINQ just select the last value from the data source.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 45, 56, 89, 56, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> Last = marks.Last();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">"Last Element "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> + Last);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">As you try example in first same example you can try with
last. The difference is that it will show last element.</span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com0tag:blogger.com,1999:blog-6758466566776686272.post-54792540458239660232013-07-25T13:04:00.000-07:002013-07-25T14:35:23.489-07:00Jagged array using LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Written By:-<a href="https://www.facebook.com/isha.malhotra3388" target="_blank">Isha Malhotra</a> </span></span><br />
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Our Website:-<a href="http://www.techaltum.com/" target="_blank">www.techaltum.com</a> </span></span></div>
<b><u><span lang="EN-IN" style="font-size: 26.0pt; line-height: 115%;">Jagged
array using LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span>
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">We
can also traverse jagged array using LINQ. <o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Following is the jagged array:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[][]
jarray =</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[3][];<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jarray[0] = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[3] { 4,
5, 6 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jarray[1] = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[2] { 7,
8 };<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> jarray[2] = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">[4] { 9, 10, 34, 12 };</span><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Suppose I have to show all even elements then
we will <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Traverse the jagged array using LINQ in
following manner:-</span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[][]
jarray =</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[3][];<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jarray[0] = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[3] { 4,
5, 6 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jarray[1] = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[2] { 7,
8 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jarray[2] = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[4] { 9,
10, 34, 12 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">IEnumerable</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jar </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jarray<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_jar
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jar<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">where</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_jar
% 2 == 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
res_jar;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_data </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(res_data);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"></span></u></b></div>
<a name='more'></a><b><u><br /></u></b>
<br />
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Another
way to traverse the jagged array using LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">for</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> i = 0;
i < jarray.Length; i++)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">IEnumerable</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> res_for = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jar </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
jarray[i]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">where</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jar % 2
== 0<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> jar;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_data </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_for)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(res_data);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Similarly
you can traverse the 2-d and 3-d array using LINQ</span><span lang="EN-IN">.<o:p></o:p></span></div>
<br /></div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com0tag:blogger.com,1999:blog-6758466566776686272.post-76969129443308382522013-07-13T13:01:00.001-07:002013-07-25T14:36:01.047-07:00Use of long count in LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Written By:-<a href="https://www.facebook.com/isha.malhotra3388" target="_blank">Isha Malhotra</a> </span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Our Website:-<a href="http://www.techaltum.com/" target="_blank">www.techaltum.com</a></span></span></div>
<b><u><span style="font-size: 36.0pt; line-height: 115%;">Use of long count in
LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Long count
is similar to count as it works same but the only difference between them is
that long count returns a 64 bit integer.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">Int64</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">
res = marks.LongCount(x => x % 2 == 0);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"> OR<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">long</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_long = marks.LongCount(x => x % 2 == 0);<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> Response.Write(res_long);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">The output of this code will be 5.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"></span><br />
<a name='more'></a><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Similarly we can apply this on generics, and database
too.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">On
Generics:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> dt = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=1, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"isha"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=2, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"sneha"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=89},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=3, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"rahul"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=4, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"renu"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=5, student=</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"sapna"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">, per=89}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">Int64</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">
count_res = dt.LongCount(x => x.per > 50);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">On
Database:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> </span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">Int64</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">
res_count = dc.GetTable<</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">>().LongCount(x => x.id > 8);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Kindly read <a href="http://isha-linq.blogspot.in/2013/06/linq-hour-5-queries-using-linq.html" target="_blank">Hour 5</a> to article to get the implementation
of database and use of get table.<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com0tag:blogger.com,1999:blog-6758466566776686272.post-88256685261238048202013-06-29T13:10:00.000-07:002013-07-25T14:36:21.187-07:00LINQ Hour 5-3 Skip/SkipWhile and Take/TakeWhile in LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Written By:-<a href="https://www.facebook.com/isha.malhotra3388" target="_blank">Isha Malhotra</a> </span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Our Website:-<a href="http://www.techaltum.com/" target="_blank">www.techaltum.com</a></span></span></div>
<b><u><span lang="EN-IN" style="font-size: 22.0pt; line-height: 115%;">Skip/SkipWhile
and Take/TakeWhile<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 22.0pt; line-height: 115%;">Skip <o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Skip
in LINQ is used to skip values from the beginning. We pass a numeric value to
skip which represent that how many values we need to skip.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 18.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 18.0pt; line-height: 115%;">For example<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Skip with array<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks
= </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
data_skip = (</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_skip </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> marks<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">orderby</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_skip<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_skip).Skip(3);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Result
using skip and skip count is 3 <br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_data_skip </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data_skip)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> { <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(res_data_skip+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"
"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Output<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_7" o:spid="_x0000_i1031" style="height: 75pt; mso-wrap-style: square; visibility: visible; width: 255pt;" type="#_x0000_t75">
<v:imagedata o:title="skip-1" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFUkDkTG7OX96rOOguTP5U-3rUHbFPQw-aWC3aYF6wGdkGMA_7qxhqywk_R7dtBedi8_crl4k7usgXGEWo_nwYoHwciuqzQOtUyuv5GWpl8VNcF2z971eHGRLSDWpL5IV9mI9E6U83IaI/s340/skip-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="188" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhFUkDkTG7OX96rOOguTP5U-3rUHbFPQw-aWC3aYF6wGdkGMA_7qxhqywk_R7dtBedi8_crl4k7usgXGEWo_nwYoHwciuqzQOtUyuv5GWpl8VNcF2z971eHGRLSDWpL5IV9mI9E6U83IaI/s640/skip-1.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Figure
1<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">It
simple arrange in ascending order and then skip 3 records as we gave 3 as input
in the skip.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 26.0pt; line-height: 115%;"></span></u></b></div>
<a name='more'></a><br />
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 26.0pt; line-height: 115%;">Take<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Take
is used to take the value from the beginning according to your count. It will
work like top command which we use in SQL.<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">For
Example:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">//it will take first five value
from the array</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data_take = (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">from</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_take </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> marks<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">select</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_take).Take(5);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_data_take </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data_take)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(res_data_take + </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">" "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 20.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 20.0pt; line-height: 115%;">Skipwhile with array<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">We
pass lambda expression to the skipwhile which is the condition. It will start
skipping the value from the beginning till the condition will be satisfied. As
it will find the record which do not match the condition it will stop skipping.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks
= </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
data_skip = (</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_skip </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> marks<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_skip).SkipWhile(x =>x%2!=0 );<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"use
of skip while <br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_data_skip </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data_skip)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> { <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(res_data_skip+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"
"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Output:-<o:p></o:p></span></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shape id="Picture_x0020_8" o:spid="_x0000_i1030" style="height: 68.25pt; mso-wrap-style: square; visibility: visible; width: 241.5pt;" type="#_x0000_t75">
<v:imagedata o:title="skip-2" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuc0IPvSHsx3KUEcEFGBeJMf0h28VBi5efQtXk46nA_TM3V65CZDQOU9wQ49IJvGMWkjFok64HXcKrgGwz1Sk0T4WckYxtbRaK9JkEoCNq05MAvsrJ-cjWRqw3lxvtljYDWehH3Hm2xDQ/s322/skip-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjuc0IPvSHsx3KUEcEFGBeJMf0h28VBi5efQtXk46nA_TM3V65CZDQOU9wQ49IJvGMWkjFok64HXcKrgGwz1Sk0T4WckYxtbRaK9JkEoCNq05MAvsrJ-cjWRqw3lxvtljYDWehH3Hm2xDQ/s640/skip-2.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Figure
2<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">As
you can see that it skipped the value till it’s satisfying the condition as it
encountered the value 78 which do not satisfy the condition so it stopped
skipping the value and select the rest of the records.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">TakeWhile</span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">TakeWhile
select the data till the condition will be true.<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">For
Example:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] marks = </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">new</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: green; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">//it will take first five value
from the array</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data_take = (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">from</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_take </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> marks<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">select</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_take).TakeWhile(x => x % 2
!= 0);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(</span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">"use
of take while <br/>"</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">foreach</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> (</span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">int</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res_data_take </span><span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">in</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> data_take)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(res_data_take + </span><span style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-ansi-language: EN-US; mso-highlight: white;">" "</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">Output:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14pt;"><v:shape id="Picture_x0020_10" o:spid="_x0000_i1029" style="height: 72.75pt; mso-wrap-style: square; visibility: visible; width: 264.75pt;" type="#_x0000_t75">
<v:imagedata o:title="take1" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png">
</v:imagedata></v:shape></span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigLltA3UrYD2oQO-cB-4zVeeUKHDVk3Xxg1akmjFwRGsVM5abZtrFWBCUVUsB5QbGypsbV3vKxhPliaxcTsdBAIvwW6BYdk189C-uQ-Z0AshD7Nb7xGmfPh17a1zF0AN08YWthMnCYaaQ/s353/skip-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="180" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEigLltA3UrYD2oQO-cB-4zVeeUKHDVk3Xxg1akmjFwRGsVM5abZtrFWBCUVUsB5QbGypsbV3vKxhPliaxcTsdBAIvwW6BYdk189C-uQ-Z0AshD7Nb7xGmfPh17a1zF0AN08YWthMnCYaaQ/s640/skip-3.png" width="640" /></a></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">Figure 3<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;"> </span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Skip with Generics(List)<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> dt = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=1, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"isha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=2, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"sneha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=89},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=3, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"rahul"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=4, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"renu"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=5, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"sapna"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=89}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">//use of skip</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res = (</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> record </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> dt<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
record).Skip(1);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Exampe
of Skip <br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
(</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> skip_data </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Roll
No:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> + skip_data.roll_no + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">" Student:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> + skip_data.student + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">" per:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> + skip_data.per + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Output:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shape id="Picture_x0020_9" o:spid="_x0000_i1028" style="height: 114.75pt; mso-wrap-style: square; visibility: visible; width: 241.5pt;" type="#_x0000_t75">
<v:imagedata o:title="skip-4" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOY4ZcHfzpWJj2oXRxhFJZ52AaXijdezyjANjf-mUOOVvg-PKVbjgiUs1YwCvL8Z6ObmhEBdslwYHjQ56mrIVuAfnUHwGZky8_3_UHfGDVFyP0lQF3kK6SOKuglC7f5iDmapBCW4qLJu4/s336/skip-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiOY4ZcHfzpWJj2oXRxhFJZ52AaXijdezyjANjf-mUOOVvg-PKVbjgiUs1YwCvL8Z6ObmhEBdslwYHjQ56mrIVuAfnUHwGZky8_3_UHfGDVFyP0lQF3kK6SOKuglC7f5iDmapBCW4qLJu4/s640/skip-4.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Figure
4<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">It
simply skips one record from the beginning.<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Similarly
you can use take.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Use of SkipWhile with Genrics<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">> dt = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=1, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"isha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=2, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"sneha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=89},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=3, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"rahul"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=4, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"renu"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">{roll_no=5, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"sapna"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">,
per=89}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">//use of skip while with two condition</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res = (</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> record </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> dt<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
record).SkipWhile(x => x.per > 50 && x.roll_no==1);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Exampe
of Skip while <br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
(</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> skip_data </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"Roll
No:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> + skip_data.roll_no + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">" Student:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> + skip_data.student + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">" per:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> + skip_data.per + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 14.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 14pt; line-height: 115%;">Output:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shape id="Picture_x0020_4" o:spid="_x0000_i1027" style="height: 111.75pt; mso-wrap-style: square; visibility: visible; width: 243pt;" type="#_x0000_t75">
<v:imagedata o:title="skip-4" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image005.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggBlMcPSoA3i2XcwmS7ZIyhiRWO4FQDC2nPGvJ7PbFi-__-bgPIaDTZvmB7X4rK2qn8kPSsXR7vH0PODGDQ7f1QI8LHAsr2D1gtKnLAygGC3ID89UuDFkZHn9E-z5cgZK8Cgd49dzL1cI/s324/skip-5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="300" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEggBlMcPSoA3i2XcwmS7ZIyhiRWO4FQDC2nPGvJ7PbFi-__-bgPIaDTZvmB7X4rK2qn8kPSsXR7vH0PODGDQ7f1QI8LHAsr2D1gtKnLAygGC3ID89UuDFkZHn9E-z5cgZK8Cgd49dzL1cI/s640/skip-5.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Figure
5<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">As
we have passed two conditions i.e roll number will be 1 and per will be greater
than 50. So it will skipped the records till the condition is satisfying<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Similarly
we can use skip with database too.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal">
<span style="background: white; color: blue; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-highlight: white;">var</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;"> res = dc.GetTable<</span><span style="background: white; color: #2b91af; font-family: Consolas; font-size: 14.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-highlight: white;">Class1</span><span style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 14pt; line-height: 115%;">>().Skip(3);</span><span style="font-family: Consolas; font-size: 14pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 14pt; line-height: 115%;">hope you enjoyed the article.</span><span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com0tag:blogger.com,1999:blog-6758466566776686272.post-88622772936570029582013-06-14T09:46:00.002-07:002013-07-25T14:36:37.636-07:00LINQ Hour 5-2 Sorting in LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Written By:-<a href="https://www.facebook.com/isha.malhotra3388" target="_blank">Isha Malhotra</a> </span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Our Website:-<a href="http://www.techaltum.com/" target="_blank">www.techaltum.com</a></span></span></div>
<b><u><span lang="EN-IN" style="font-size: 26.0pt; line-height: 115%;">Sorting
in LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">To
sort data in LINQ we use orderby in the following manner:-<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Sorting with Array<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">[] marks
= </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">// it will sort in ascending order</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
sort_asc = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_asc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> marks<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">orderby</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_asc<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_asc;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">//it will sort in descending order</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
sort_desc = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_desc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> marks<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">orderby</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_desc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">descending</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_desc;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Ascending
order result <br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_asc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> sort_asc)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(res_asc + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"
"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"<br/>descending
order result <br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_desc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> sort_desc)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(res_desc + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"
"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">The output
of the code is as follows:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 12.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_9" o:spid="_x0000_i1030" style="height: 97.5pt; mso-wrap-style: square; visibility: visible; width: 260.25pt;" type="#_x0000_t75">
<v:imagedata o:title="query-5" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKoxSUTqP1DEACberGj1hnahvo5WtdsyDRy5xSb2y-De55JjjQ2hu4ap38-45QzpBPnpls9U7uwyhcMoZa8JmNsQyqHWFfqqDiP2i-Hgi2F3x59KYBVT0btoaVnc8GdtCTWhhYIkHMuBc/s1600/query-5.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgKoxSUTqP1DEACberGj1hnahvo5WtdsyDRy5xSb2y-De55JjjQ2hu4ap38-45QzpBPnpls9U7uwyhcMoZa8JmNsQyqHWFfqqDiP2i-Hgi2F3x59KYBVT0btoaVnc8GdtCTWhhYIkHMuBc/s640/query-5.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Figure
1<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;"></span></u></b></div>
<a name='more'></a><b><u><br /></u></b>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;">Sorting with Generics:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">> dt = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=1, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"isha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=2, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"sneha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=89},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=3, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"rahul"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=4, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"renu"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=5, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"sapna"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=89}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> dt<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">orderby</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc.per<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Ascending
order on the basis of Per<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
(</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_after_sort </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> { <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Roll
No:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_after_sort.roll_no+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">" Student:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_after_sort.student+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">" per:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_after_sort.per+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> }</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">The output
of this code as follows:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><v:shape id="Picture_x0020_10" o:spid="_x0000_i1029" style="height: 127.5pt; mso-wrap-style: square; visibility: visible; width: 243.75pt;" type="#_x0000_t75">
<v:imagedata o:title="query-6" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ-UhcHzpybkAxS0zpNufHFwVTT_nxwb5tvR1ljQc9g8i1gYQITrpTLTV69Ahp6gKF52VEeDSZKiEAqxsWGKWtinvHwjgO6NV_PLZGWl45NZuPR2FsGSomQPsdtYKLq3loVluDcRvJHYE/s1600/query-6.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="336" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjZ-UhcHzpybkAxS0zpNufHFwVTT_nxwb5tvR1ljQc9g8i1gYQITrpTLTV69Ahp6gKF52VEeDSZKiEAqxsWGKWtinvHwjgO6NV_PLZGWl45NZuPR2FsGSomQPsdtYKLq3loVluDcRvJHYE/s640/query-6.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">Figure 2<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">Similarly if we want to perform descending
ordering then we will use following code:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> dt<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">orderby</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc.per </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">descending</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> res_sort_asc;</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">Sorting
on the basis of more than one column<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">When we want to sort on the basis of more
than one column then we will use following code:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">> dt = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=1, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"isha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=2, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"sneha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=89},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=3, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"rahul"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=4, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"renu"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=34},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=5, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"sapna"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=89}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">//sort first on the basis of per then by student</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">from</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> dt<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">orderby</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc.per, res_sort_asc.student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">select</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_sort_asc;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Ascending
order on the basis of Per and student<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
(</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_after_sort </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> { <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Roll
No:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_after_sort.roll_no+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">" Student:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_after_sort.student+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">" per:- "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_after_sort.per+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">The output
of this code as follows:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><v:shape id="Picture_x0020_8" o:spid="_x0000_i1028" style="height: 129pt; mso-wrap-style: square; visibility: visible; width: 254.25pt;" type="#_x0000_t75">
<v:imagedata o:title="query-7" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqgKu8f74zcPgFy403DErfI96Q893obtytr5_unnWqHmJxM0HrrYo3eF2lOFz93KuU20V9NFdAT1hhrFzEH3kDURCUEoCRujmUHEjhhDFxJ5GljTIP0AvNyJiGF-5cbSZzYW4G7cjw-Sc/s1600/query-7.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="322" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqgKu8f74zcPgFy403DErfI96Q893obtytr5_unnWqHmJxM0HrrYo3eF2lOFz93KuU20V9NFdAT1hhrFzEH3kDURCUEoCRujmUHEjhhDFxJ5GljTIP0AvNyJiGF-5cbSZzYW4G7cjw-Sc/s640/query-7.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">Figure 3<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 18pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 18pt; line-height: 115%;">Sorting
with Database<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">If we want to sort data on the basis of any
column then we use the following code in LINQ:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">DataContext</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> dc = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">DataContext</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Data
Source=.;Initial Catalog=TechAltum;Integrated Security=True"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res =
dc.GetTable<</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">Class1</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">>().OrderBy(x => x.no_of_prod);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">//sorting on the basis of no of pord</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">foreach</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
(</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">Class1</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res_data </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">in</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> { <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Prod
Year="</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_data.prod_year+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">", Dept="</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_data.dept+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">", No_of_prod="</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">+res_data.no_of_prod+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">The output
of this code is as follows:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><v:shape id="Picture_x0020_11" o:spid="_x0000_i1027" style="height: 160.5pt; mso-wrap-style: square; visibility: visible; width: 260.25pt;" type="#_x0000_t75">
<v:imagedata o:title="query-8" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image004.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjmT7LaL7MbXzE2IUkyDj3nJY6H0C8RyRTCFSrMRenXGzO7WQ8Bmz4DWScLFqtybdDl8NLZXBw7SJmeXLlQKj7b9kM5kW_Wf0ER4YFegpi3jqoxkP3pld6mcKfVyQXN3D-ndGwSE7rrRg/s1600/query-8.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="396" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjjmT7LaL7MbXzE2IUkyDj3nJY6H0C8RyRTCFSrMRenXGzO7WQ8Bmz4DWScLFqtybdDl8NLZXBw7SJmeXLlQKj7b9kM5kW_Wf0ER4YFegpi3jqoxkP3pld6mcKfVyQXN3D-ndGwSE7rrRg/s640/query-8.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">Figure 4<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">Sorting
in descending order:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> res = dc.GetTable<</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">Class1</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;">>().OrderByDescending(x
=> x.no_of_prod);</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">sorting
on the basis of more than one columne:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">var</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> res = dc.GetTable<</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">Class1</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;">>().OrderByDescending(x
=> x.no_of_prod).ThenBy(x => x.prod_year);</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;">Hope you enjoyed the article. For any query
you can mail me at info@techaltum.com<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com19tag:blogger.com,1999:blog-6758466566776686272.post-46274990156114669022013-06-14T07:44:00.000-07:002013-07-25T14:36:52.734-07:00LINQ Hour 5 -1 Aggregate function in LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Written By:-<a href="https://www.facebook.com/isha.malhotra3388" target="_blank">Isha Malhotra</a> </span></span></div>
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Our Website:-<a href="http://www.techaltum.com/" target="_blank">www.techaltum.com</a></span></span></div>
<b><u><span lang="EN-IN" style="font-size: 20.0pt; line-height: 115%;">Aggregate
function using LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">We
use many aggregate functions like sum, count, average, min, and max. In LINQ we
can use this function in the following manner:-<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">SUM<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">If
we want to perform sum aggregate function then we will implement the following
queries:-<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Sum with array<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">[] marks
= </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">//simple sum without condition</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> res =
marks.Sum();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">//sum with condition</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
res_with_where = marks.Where(cond => cond > 50).Sum();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Sum without condition= "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> + res + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">"Sum with condition="</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;">+ res_with_where+</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;">);</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><b><u>Output of this code as follows:-</u></b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 12.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_7" o:spid="_x0000_i1029" style="height: 75.75pt; mso-wrap-style: square; visibility: visible; width: 246pt;" type="#_x0000_t75">
<v:imagedata o:title="query-2" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYe3cBgxD6EOcJDL-xfg-YQ9jQVBXSLsMsodbtcoz12_Horpg2863WTu3_zssAAqu5I0cRE3IifmOR8dXdomDrcdhGRjznu0bJ6x6BCSG2ZvbZNOTyISIb09M73216H1wA9AqkMoFiSQI/s1600/query-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="200" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgYe3cBgxD6EOcJDL-xfg-YQ9jQVBXSLsMsodbtcoz12_Horpg2863WTu3_zssAAqu5I0cRE3IifmOR8dXdomDrcdhGRjznu0bJ6x6BCSG2ZvbZNOTyISIb09M73216H1wA9AqkMoFiSQI/s640/query-2.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Figure
1<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<a name='more'></a><br />
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Sum with Generics<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">> dt = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=1, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"isha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=2, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"neha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=89},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">{roll_no=3, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"rahul"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">,
per=34}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> per_sum
= dt.Sum(x => x.per);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
per_sum_with_conditon = dt.Where(stu => stu.student.EndsWith(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"ha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">)).Sum(x => x.per);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Sum
without condition= "</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> +
per_sum + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">"Sum with condition="</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> + per_sum_with_conditon + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;">);</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><b><u>Output of this code as follows:-</u></b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 12.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shape id="Picture_x0020_8" o:spid="_x0000_i1028" style="height: 70.5pt; mso-wrap-style: square; visibility: visible; width: 243pt;" type="#_x0000_t75">
<v:imagedata o:title="query-3" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image002.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih2PG1ttzWOoujLSoStDaXQyidyfBRTHvb-yZi_fNFVGJXUBcJMh4Stzr3yRHelM22ZhU5SbnHyThaZXSxjQdNTT7A-jztz9m4NBxHiYy1ovOfTYDyZO4wAWfTU4Vv9xaC3LFpnap9ZTo/s1600/query-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="184" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEih2PG1ttzWOoujLSoStDaXQyidyfBRTHvb-yZi_fNFVGJXUBcJMh4Stzr3yRHelM22ZhU5SbnHyThaZXSxjQdNTT7A-jztz9m4NBxHiYy1ovOfTYDyZO4wAWfTU4Vv9xaC3LFpnap9ZTo/s640/query-3.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Figure
2<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Sum with database:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">DataContext</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> dc = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">DataContext</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Data
Source=.;Initial Catalog=TechAltum;Integrated Security=True"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">//sum without condition</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
sum_without_cond = dc.GetTable<</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">Class1</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">>().Sum(prod_sum => prod_sum.no_of_prod);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">//sum with conditon</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
sum_with_cond = dc.GetTable<</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">Class1</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">>().Where(cond => cond.prod_year ==
2001).Sum(prod_sum => prod_sum.no_of_prod);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">
Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"Sum
without conditon="</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;"> +
sum_without_cond + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt;">);<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> Response.Write(</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">"Sum with conditon="</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;"> + sum_with_cond + </span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 12.0pt; line-height: 115%; mso-highlight: white;">"<br/>"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 12pt; line-height: 115%;">);</span><span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 12pt; line-height: 115%;"><b><u>Output of this code as follows:-</u></b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 12.0pt; line-height: 115%; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shape id="Picture_x0020_4" o:spid="_x0000_i1027" style="height: 80.25pt; mso-wrap-style: square; visibility: visible; width: 249pt;" type="#_x0000_t75">
<v:imagedata o:title="query-4" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image003.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiA9UcoqY1XXbPUWiyGknyJABXAfEvrJtWfxpHQw8iDpXDL_7L_pLuO-6GEte3L1USb5P9ZrTdnwQHqVDXi9J6bassQWEUdv6RpTUke9ltfZYH4d-AFvxADAFHIGtfGxOB2IrRaQFs3iaA/s1600/query-4.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="208" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiA9UcoqY1XXbPUWiyGknyJABXAfEvrJtWfxpHQw8iDpXDL_7L_pLuO-6GEte3L1USb5P9ZrTdnwQHqVDXi9J6bassQWEUdv6RpTUke9ltfZYH4d-AFvxADAFHIGtfGxOB2IrRaQFs3iaA/s640/query-4.png" width="640" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Figure
3<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">Similarly
we can perform max, min, average and count using LINQ.<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 12.0pt; line-height: 115%;">For
any query you can mail me at info@techaltum.com<o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com1tag:blogger.com,1999:blog-6758466566776686272.post-12135981338029212192013-06-14T07:37:00.000-07:002013-07-25T14:37:08.588-07:00LINQ Hour 5 - Queries using LINQ<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Written By:-<a href="https://www.facebook.com/isha.malhotra3388" target="_blank">Isha Malhotra</a> </span></span></div>
<span lang="EN-IN" style="font-size: 20.0pt; line-height: 115%;"></span><br />
<div style="text-align: left;">
<span style="font-size: large;"><span style="line-height: 18.18181800842285px;">Our Website:-<a href="http://www.techaltum.com/" target="_blank">www.techaltum.com</a></span></span></div>
<span lang="EN-IN" style="font-size: 20.0pt; line-height: 115%;"><u><b>Perform different functionality (QUERY)
using LINQ</b></u><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN">As in the previous article I already
discussed about select, insert, update and delete. I also discussed with where
clause, order by, grouping. In this hour I will discuss about different
operation which we can perform using LINQ. As we know we can perform this
functionality on array, generics, database, xml etc. so here I am taking the
example of array, generics and database. I will discuss xml separately. <o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN">To work with this functionality I am taking
the following source:-<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 26.0pt; line-height: 115%;">Array<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Using following int array:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">[] marks = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; line-height: 115%; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">[] { 23, 45, 78, 90, 56, 89, 10, 32 };</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 24pt; line-height: 115%;">Generics:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;">Using following class to implement generics:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">
roll_no;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">
student;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> per;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">}</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;">And following list:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">> dt = </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">List</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{roll_no=1, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"isha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">,
per=100},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{roll_no=2, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"neha"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">,
per=89},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">new</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">data</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{roll_no=3, student=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"rahul"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">,
per=34}<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;"> };</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 28.0pt; line-height: 115%;">Database<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Using following table:-<o:p></o:p></span></div>
<div class="MsoNormal">
<v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_4" o:spid="_x0000_i1027" style="height: 149.25pt; mso-wrap-style: square; visibility: visible; width: 203.25pt;" type="#_x0000_t75">
<v:imagedata o:title="query-1" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape><span lang="EN-IN"><o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU3Jxy2Ct16qcQEyKbhfyy02pXul6JRBOF2d9abHO39muwhpxcd1xdxdtqgJmjZrLRhQQfxWKLOrK7Qvhzr-q0oGlSGEGy3V1lSXncanf3SD78AvY128UVEvD0DioJIIxAE6oU-TbwcU0/s1600/query-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgU3Jxy2Ct16qcQEyKbhfyy02pXul6JRBOF2d9abHO39muwhpxcd1xdxdtqgJmjZrLRhQQfxWKLOrK7Qvhzr-q0oGlSGEGy3V1lSXncanf3SD78AvY128UVEvD0DioJIIxAE6oU-TbwcU0/s1600/query-1.png" /></a></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN">Figure 1<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN">And create its class to mapping this table
which is as follows:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">[</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Table</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">(Name=</span><span lang="EN-IN" style="background: white; color: #a31515; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">"prod_rep"</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">class</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Class1</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> [</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Column</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> id;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> [</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Column</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">
prod_year;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> [</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Column</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">string</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> dept;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> [</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">Column</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 9.5pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt;">
no_of_prod;<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 9.5pt; line-height: 115%;">}</span><span lang="EN-IN" style="font-family: Consolas; font-size: 9.5pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-family: Consolas;"><span style="font-size: 12.727272033691406px; line-height: 14.545454025268555px;">click on the following link to perform different functionality:-</span></span><br />
<span style="font-family: Consolas;"><span style="font-size: 12.727272033691406px; line-height: 14.545454025268555px;"><br /></span></span>
<span style="font-family: Consolas;"><span style="font-size: 12.727272033691406px; line-height: 14.545454025268555px;"><a href="http://isha-linq.blogspot.in/2013/06/linq-hour-5-1-aggregate-function-in-linq.html" target="_blank">Part 1 Aggregate function in LINQ</a></span></span><br />
<span style="font-family: Consolas;"><br /></span>
<span style="font-family: Consolas;"><a href="http://isha-linq.blogspot.in/2013/06/linq-hour-5-2-sorting-in-linq.html" target="_blank">Part 2 Sorting in LINQ</a></span><br />
<br />
<a href="http://isha-linq.blogspot.in/2013/06/linq-hour-5-3-skipskipwhile-and.html" target="_blank">Part 3 Take / TakeWhile and Skip / SkipWhile</a></div>
<br />
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com0tag:blogger.com,1999:blog-6758466566776686272.post-414572931868365312013-06-02T01:08:00.002-07:002013-06-02T01:08:49.137-07:00LINQ-Hour 4 Lambda Expression Part 1<div dir="ltr" style="text-align: left;" trbidi="on">
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span lang="EN-IN" style="font-size: 24.0pt; line-height: 115%;">LAMBDA
Expression Part 1 <o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;">A
lambda expression is an anonymous function. Using lambda expression we can
create function for delegate and we can also create expression tree type.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 22.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 22.0pt; line-height: 115%;">Syntax of Lambda Expression<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 14.0pt; line-height: 115%;">Input
parameter=>programming statements<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 22.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 22.0pt; line-height: 115%;">Lambda Expression Example with
Delegate<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;">If
you know how to use delegate then you know we have to pass the reference of
method to that delegate which matches the signature. But when we use lambda
expression we can give the definition of that method directly to the delegate
which is as follows:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//create a delegate which take one int as input and return
one int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">delegate</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Del_example</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> x);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">partial</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">class</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Default2</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> : System.Web.UI.</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Page</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">protected</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">void</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
Page_Load(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">object</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> sender, </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">EventArgs</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//create object of delegate and instead passing the
ref of method i simply pass</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//the complete definition using lambda expression</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Del_example</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> cal_square = x => x * x;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//execute the delgate</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
res=cal_square(5);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> Response.Write(res);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt; line-height: 115%;">}</span><span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
</div>
<a name='more'></a><br /><br />
<div class="MsoNormal">
<b><u><span lang="EN-IN" style="font-size: 22.0pt; line-height: 115%;">Let’s take another example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;">In
this example we are calculating the power using lambda expression<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">using</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//create a delegate which take one int as input and return
one int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">delegate</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Del_example</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> x);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//create another delegate to calculate power</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">delegate</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">del_Power</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> b, </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> p);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">public</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">partial</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">class</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Default2</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> : System.Web.UI.</span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Page</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">protected</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">void</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
Page_Load(</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">object</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> sender, </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">EventArgs</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//create object of delegate and instead passing the
ref of method i simply pass</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//the complete definition using lambda expression</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">Del_example</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> cal_square = x => x * x;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//execute the delgate</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
res=cal_square(5);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
Response.Write(res);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//this is another exampel of lembda expression </span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//power calculation</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: #2b91af; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">del_Power</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> dp = (b, p) => {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: green; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">//as you can see we create variable in lembda
expression</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> data =
1;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">for</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> (</span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> i = 1;
i < p; i++)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> data
= data * b;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">return</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> data;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> </span><span lang="EN-IN" style="background: white; color: blue; font-family: Consolas; font-size: 16.0pt; mso-highlight: white;">int</span><span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;">
res_power = dp(3, 5);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> Response.Write(res_power);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="background-color: white; background-position: initial initial; background-repeat: initial initial; font-family: Consolas; font-size: 16pt; line-height: 115%;">}</span><span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;"><o:p></o:p></span></div>
<br />
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 20.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 20.0pt; line-height: 115%;">In
the next article I will discuss how to use lambda expression using LINQ<o:p></o:p></span></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com0tag:blogger.com,1999:blog-6758466566776686272.post-22990890976102026972013-05-19T01:42:00.000-07:002013-05-19T01:42:36.768-07:00LINQ- Hour 3 (LINQ to XML)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span lang="EN-IN" style="font-size: 24.0pt; line-height: 115%;">LINQ to
XML<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span lang="EN-IN" style="font-size: 16.0pt; line-height: 115%;">When
we interact with XML using LINQ then it is known as LINQ to XML.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-size: 16.0pt;">To work with XML in LINQ you have to add a namespace <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> System.Xml.Linq. <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<u><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">I am taking the following xml
file for an example:-<o:p></o:p></span></u></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><?xml version=”1.0”
encoding=”utf-8” ?><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><Techaltum><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><student
Code=”101”><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <name>isha
malhotra</name><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <id>
1 </id><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <course>
asp.net </course><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> </student><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><student
Code=”102”><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <name>Avi
malhotra</name><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <id>
2 </id><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <course>
Web Designing </course><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> </student><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt; text-indent: 0.5in;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><student
Code=”103”><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <name>Neha</name><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <id>
3 </id><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <course>
Java </course><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> </student><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"></Techaltum><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">If I consider this xml file then
in this file first line is declaration. Techaltum is an element and in student
element code is attribute.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">First I will discuss how to
declare all these in LINQ.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">Syntax
of Declaration in LINQ:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 16.0pt;">XDeclaration</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> dec = <span style="color: blue;">new</span> <span style="color: #2b91af;">XDeclaration</span>(<span style="color: #a31515;">"1.0"</span>, <span style="color: #a31515;">"utf-8"</span>,
<span style="color: #a31515;">"yes"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"></span></div>
<a name='more'></a><br /><br />
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">Syntax
of Element in LINQ:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 16.0pt;">XElement</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> student = <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">""</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">Syntax
of Attribute in LINQ:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 16.0pt;">XAttribute</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> code;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">Syntax
of comment in LINQ:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: #2b91af; font-family: Consolas; font-size: 16.0pt;">XComment</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> comm = <span style="color: blue;">new</span> <span style="color: #2b91af;">XComment</span>(<span style="color: #a31515;">""</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><u><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">Create
complete xml file using LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">
System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">
System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">using</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> System.Xml.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="color: blue; font-family: Consolas; font-size: 16.0pt;">public</span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> : System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span>
sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: #2b91af;">XDocument</span>
techaltum_doc = <span style="color: blue;">new</span> <span style="color: #2b91af;">XDocument</span>(<span style="color: blue;">new</span> <span style="color: #2b91af;">XDeclaration</span>(<span style="color: #a31515;">"1.0"</span>, <span style="color: #a31515;">"utf-8"</span>,
<span style="color: #a31515;">"yes"</span>),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">new</span>
<span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"Techaltum"</span>,<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"student"</span>, <span style="color: blue;">new</span>
<span style="color: #2b91af;">XAttribute</span>(<span style="color: #a31515;">"code"</span>,
<span style="color: #a31515;">"101"</span>),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"name"</span>, <span style="color: #a31515;">"Isha
Malhotra"</span>), <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"id"</span>,
<span style="color: #a31515;">"1"</span>), <span style="color: blue;">new</span>
<span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"course"</span>,
<span style="color: #a31515;">"asp.net"</span>)),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"student"</span>, <span style="color: blue;">new</span>
<span style="color: #2b91af;">XAttribute</span>(<span style="color: #a31515;">"code"</span>,
<span style="color: #a31515;">"102"</span>),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"name"</span>, <span style="color: #a31515;">"Avi
Malhotra"</span>), <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"id"</span>,
<span style="color: #a31515;">"2"</span>), <span style="color: blue;">new</span>
<span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"course"</span>,
<span style="color: #a31515;">"web Desiging"</span>)),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"student"</span>, <span style="color: blue;">new</span>
<span style="color: #2b91af;">XAttribute</span>(<span style="color: #a31515;">"code"</span>,
<span style="color: #a31515;">"103"</span>),<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"name"</span>, <span style="color: #a31515;">"Neha"</span>),
<span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"id"</span>, <span style="color: #a31515;">"3"</span>),
<span style="color: blue;">new</span> <span style="color: #2b91af;">XElement</span>(<span style="color: #a31515;">"course"</span>, <span style="color: #a31515;">"Java"</span>))<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> )<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> );<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">//storage of file<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> techaltum_doc.Save(Server.MapPath(<span style="color: #a31515;">"xml"</span>)+<span style="color: #a31515;">"/abc.xml"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">To store this file I simply
created the folder name xml in my visual studio. After executing this code
refresh this folder and you will get your file in this folder.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnkmGyTWmNXGcHxOqyInO2pFtFP4MGwLVw2vNFVxEAFhZnFXBB5AoJvaMH8lHde-diBgQpeMQvEd_3aCJXnqY9W7ohvNh1HNU8eAb7KV73mlKUj_vtBVys-YFJ7hVWV2Xa8KqBlv9agq4/s1600/xml-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="578" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjnkmGyTWmNXGcHxOqyInO2pFtFP4MGwLVw2vNFVxEAFhZnFXBB5AoJvaMH8lHde-diBgQpeMQvEd_3aCJXnqY9W7ohvNh1HNU8eAb7KV73mlKUj_vtBVys-YFJ7hVWV2Xa8KqBlv9agq4/s640/xml-1.png" width="640" /></a></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 16.0pt; mso-ansi-language: EN-US; mso-fareast-language: EN-US; mso-no-proof: yes;"><v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape alt="Description: C:\Users\Avi\Desktop\xml-1.png" id="Picture_x0020_4" o:spid="_x0000_i1027" style="height: 237.75pt; mso-wrap-style: square; visibility: visible; width: 262.5pt;" type="#_x0000_t75">
<v:imagedata o:title="xml-1" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape></span><span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">Figure 1<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span lang="EN-IN" style="font-family: Consolas; font-size: 16.0pt;">Hope you enjoyed the article.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com0tag:blogger.com,1999:blog-6758466566776686272.post-87788560909708748792013-04-29T14:16:00.000-07:002013-04-29T14:16:29.973-07:00LINQ-Hour 2 (LINQ to SQL)<div dir="ltr" style="text-align: left;" trbidi="on">
<br />
Written By<span class="GINGER_SOFATWARE_correct" ginger_sofatware_markguid="51c89dfa-3ba0-42fb-92b6-7deab9d35f73" ginger_sofatware_uiphraseguid="8a9fe51b-260f-4701-a314-97171f2a659c" grcontextid="::0" style="background-image: url(data:image/gif; border-bottom-left-radius: 2px; border-bottom-right-radius: 2px; border-top-left-radius: 2px; border-top-right-radius: 2px;">:</span>-Isha Malhotra(malhotra.isha3388@gmail.com)<br />
if you find this article useful then leave your comment<br />
<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span style="font-size: 36.0pt; line-height: 115%;">LINQ to SQL<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">SQL is a
structured Query Language. When we need to interact with database using LINQ
then we mapped our relational database to object oriented language using LINQ
to SQL.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">To interact
with database we use Datacontext class which is in System.Data.LINQ. this class
contains the constructor in which we have to pass the connection string.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 26.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 26.0pt; line-height: 115%;">Steps to work with LINQ to SQL<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">Step 1:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Add LINQ to
SQL Class by using Add New Item. It will add .dbml file which is database management
language.<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVRJ_NDzWvgM34ZBwD5KKZI09vnammIEdQgfy3DMeaJ3DA7bsuFsyxkGo9QRxZvVl6JM4fQsam77-3AZQ4_QXYgVseOXFERz_I_zH25Ahme-QnRZRHqR0jxf0kFf9IvSwuvrnzA697_Cc/s1600/LinqToSQL-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="366" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhVRJ_NDzWvgM34ZBwD5KKZI09vnammIEdQgfy3DMeaJ3DA7bsuFsyxkGo9QRxZvVl6JM4fQsam77-3AZQ4_QXYgVseOXFERz_I_zH25Ahme-QnRZRHqR0jxf0kFf9IvSwuvrnzA697_Cc/s640/LinqToSQL-1.png" width="640" /></a></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%; mso-no-proof: yes;"><!--[if gte vml 1]><v:shapetype id="_x0000_t75" coordsize="21600,21600"
o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f"
stroked="f">
<v:stroke joinstyle="miter"/>
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0"/>
<v:f eqn="sum @0 1 0"/>
<v:f eqn="sum 0 0 @1"/>
<v:f eqn="prod @2 1 2"/>
<v:f eqn="prod @3 21600 pixelWidth"/>
<v:f eqn="prod @3 21600 pixelHeight"/>
<v:f eqn="sum @0 0 1"/>
<v:f eqn="prod @6 1 2"/>
<v:f eqn="prod @7 21600 pixelWidth"/>
<v:f eqn="sum @8 21600 0"/>
<v:f eqn="prod @7 21600 pixelHeight"/>
<v:f eqn="sum @10 21600 0"/>
</v:formulas>
<v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"/>
<o:lock v:ext="edit" aspectratio="t"/>
</v:shapetype><v:shape id="Picture_x0020_1" o:spid="_x0000_i1026" type="#_x0000_t75"
alt="Description: D:\Data\LinqToSQL-1.png" style='width:468pt;height:339pt;
visibility:visible;mso-wrap-style:square'>
<v:imagedata src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png"
o:title="LinqToSQL-1"/>
</v:shape><![endif]--><!--[if !vml]--><!--[endif]--></span><span style="font-size: 14.0pt; line-height: 115%;"><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 1<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">Step 2:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Now add
class by using Add New Item. These classes are used to mapped your database
with object oriented. After adding the class, add the namespace
System.Data.LINQ.Mapping. Then add [Table] tag to the class and [Column] to the
variable which is as follows:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<b><span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span></b><b><span style="font-family: Consolas; font-size: 14.0pt;"> System.Data.Linq.Mapping;<o:p></o:p></span></b></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">[<span style="color: #2b91af;">Table</span>(Name=<span style="color: #a31515;">"prod_rep"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">public</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Class1</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> [<span style="color: #2b91af;">Column</span>]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> prod_year;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> [<span style="color: #2b91af;">Column</span>]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> dept;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> [<span style="color: #2b91af;">Column</span>]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span>
no_of_prod;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Prod_rep is
table name in the database and others are columns.<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">Step 3:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Now create
the object of DataContext class and pass the connection string in the
constructor. Now create the query for selecting the data from the table.<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Data.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">public</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> :
System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create the object of data context class and pass the
connection string</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: #2b91af;">DataContext</span> dc = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataContext</span>(<span style="color: #a31515;">"Data
Source=ISHA-PC;Initial Catalog=TechAltum;Integrated Security=True"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create the query for selection</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">var</span> x = <span style="color: blue;">from</span> data <span style="color: blue;">in</span> dc.GetTable<<span style="color: #2b91af;">Class1</span>>()<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
<span style="color: blue;">select</span> <span style="color: blue;">new</span>
{ Prod_year = data.prod_year, Dept = data.dept, No_of_Prod = data.no_of_prod };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//bind the data in gridview</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
GridView1.DataSource = x;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
GridView1.DataBind();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"></span></div>
<a name='more'></a><br /><br />
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">The output
of this code as follows:-<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9vAIYuaRrxMIWsGcuQjFPdFkE3EwpWjb3Ux8qUcRMCUxRtlkZ4rS2YrBiWyyv6fH4dugubZGP5IumBkjS5jAN8bxzHHTFlx_DM-ydFVeyYazWjYzsoHRG5AM06kndZueChm0FVdPupW0/s1600/LinqtoSQL-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="482" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi9vAIYuaRrxMIWsGcuQjFPdFkE3EwpWjb3Ux8qUcRMCUxRtlkZ4rS2YrBiWyyv6fH4dugubZGP5IumBkjS5jAN8bxzHHTFlx_DM-ydFVeyYazWjYzsoHRG5AM06kndZueChm0FVdPupW0/s640/LinqtoSQL-2.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Figure 2<o:p></o:p></span></div>
<div class="MsoNormal">
<b><u><span style="font-size: 24.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 24.0pt; line-height: 115%;">Insert data in Database using LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">When we need
to insert the data in SQL server using LINQ to SQL then we use the following
code:-<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">When we
insert using LINQ then your table must have primary key. So the table which I was
using not contain primary key. So I added one more column name id in the table which
is primary and auto generated (used identity). So I have to make following
changes in the class which maps my table to object oriented language which is
as follows:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Data.Linq.Mapping;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">[<span style="color: #2b91af;">Table</span>(Name=<span style="color: #a31515;">"prod_rep"</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">public</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">Class1</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> [<span style="color: #2b91af;">Column</span>]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> prod_year;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> [<span style="color: #2b91af;">Column</span>]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span> dept;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> [<span style="color: #2b91af;">Column</span>]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span>
no_of_prod;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//isdbgenerated is used for auto generated column which is
identity</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> [<span style="color: #2b91af;">Column</span>(IsPrimaryKey=<span style="color: blue;">true</span>,IsDbGenerated=<span style="color: blue;">true</span>)]<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> id;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Now use the
following code to insert data in the table:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Data.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">public</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Insert_LINQ_To_SQL</span>
: System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Button1_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create the object of data context class and pass the
connection string</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: #2b91af;">DataContext</span> dc = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataContext</span>(<span style="color: #a31515;">"Data
Source=ISHA-PC;Initial Catalog=TechAltum;Integrated Security=True"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create object of class which mapped the table in database</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: #2b91af;">Class1</span> cal_data = <span style="color: blue;">new</span>
<span style="color: #2b91af;">Class1</span>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//add data to be inserted </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
cal_data.prod_year=<span style="color: #2b91af;">Convert</span>.ToInt32(TextBox1.Text);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
cal_data.dept = TextBox2.Text;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> cal_data.no_of_prod
= <span style="color: #2b91af;">Convert</span>.ToInt32(TextBox3.Text);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//add data into the data context class for insertion</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
dc.GetTable<<span style="color: #2b91af;">Class1</span>>().InsertOnSubmit(cal_data);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
dc.SubmitChanges();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><b><u>Delete data from database using LINQ</u></b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">Use the following code to delete the data:-<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Data.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">public</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Insert_LINQ_To_SQL</span>
: System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Button1_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create the object of data context class and pass the
connection string</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: #2b91af;">DataContext</span> dc = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataContext</span>(<span style="color: #a31515;">"Data
Source=ISHA-PC;Initial Catalog=TechAltum;Integrated Security=True"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create object of class which mapped the table in database</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: #2b91af;">Class1</span> cal_data;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//set the where clause for delete the data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
cal_data = dc.GetTable<<span style="color: #2b91af;">Class1</span>>().Single(res
=> res.id == <span style="color: #2b91af;">Convert</span>.ToInt32(TextBox1.Text));<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//add object to the delete method</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
dc.GetTable<<span style="color: #2b91af;">Class1</span>>().DeleteOnSubmit(cal_data);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
dc.SubmitChanges();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"> <o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><b><u>Update data in database using LINQ</u></b><o:p></o:p></span></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">using</span><span style="font-family: Consolas; font-size: 14.0pt;"> System.Data.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 14.0pt;">public</span><span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">Insert_LINQ_To_SQL</span>
: System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Button1_Click(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create the object of data context class and pass the
connection string</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: #2b91af;">DataContext</span> dc = <span style="color: blue;">new</span>
<span style="color: #2b91af;">DataContext</span>(<span style="color: #a31515;">"Data
Source=ISHA-PC;Initial Catalog=TechAltum;Integrated Security=True"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//create object of class which mapped the table in database</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: #2b91af;">Class1</span> cal_data;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//set the where clause for update the data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
cal_data = dc.GetTable<<span style="color: #2b91af;">Class1</span>>().Single(res
=> res.id == 4);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <span style="color: green;">//add updated data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
cal_data.dept = <span style="color: #a31515;">"changeDept"</span>;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
dc.GetTable<<span style="color: #2b91af;">Class1</span>>();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">
dc.SubmitChanges();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 14.0pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<span style="font-size: 14.0pt; line-height: 115%;">hope you enjoyed the article</span></div>
<br />
</div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com3tag:blogger.com,1999:blog-6758466566776686272.post-48509662364695697172013-04-23T09:47:00.000-07:002013-04-23T13:08:01.619-07:00LINQ Training - Hour 1<div dir="ltr" style="text-align: left;" trbidi="on">
Written By<span class="GINGER_SOFATWARE_correct" ginger_sofatware_markguid="51c89dfa-3ba0-42fb-92b6-7deab9d35f73" ginger_sofatware_uiphraseguid="8a9fe51b-260f-4701-a314-97171f2a659c" grcontextid="::0">:</span>-Isha Malhotra(malhotra.isha3388@gmail.com)<br />
if you find this article useful then leave your comment<br />
<div align="center" class="MsoNormal" style="text-align: center;">
<b><u><span style="font-size: 24.0pt; line-height: 115%;"><span class="GingerNoCheckStart"></span><span class="GingerNoCheckStart"></span><span class="GingerNoCheckStart"></span>LINQ-Hour 1<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Language Integrated Query introduced in .net framework 3.5.
LINQ integrated accessibility of data and query into language. LINQ makes
easier to work with data.<o:p></o:p></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;">Advantage of LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Earlier when we connect to database, we used SQL queries as
text like if we have to select any data from table then we write following
queries:-<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
“select * from Table_name”<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
This query will be passed as text and if this query has some
syntax error then it will be showed when this query will be executed means at
runtime. But in LINQ at the time of compile time all syntax checked as it
integrate query writing in our language(C# or Vb.net)<o:p></o:p></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;">Query writing in LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
LINQ allows us to write query against all data whether it
comes from array, database, XML etc.
This is the best feature of LINQ.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Before going deep into LINQ lets run some basic queries in
LINQ using arrays and try to understand the syntax of LINQ<o:p></o:p></div>
<div class="MsoNormal">
</div>
<a name='more'></a><br />
<br />
<div class="MsoNormal">
The namespace which is used for these queries is as
follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;">For Example:-<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Let’s take the string array which contains the name of
student as follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> :
System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span> Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span>
e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//declare the array</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span>[] techaltum_student = <span style="color: blue;">new</span>
<span style="color: blue;">string</span>[] { <span style="color: #a31515;">"isha"</span>,
<span style="color: #a31515;">"avinash"</span>, <span style="color: #a31515;">"guddu"</span>, <span style="color: #a31515;">"neha
sharma"</span> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//quey using LINQ syntax</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">IEnumerable</span><<span style="color: blue;">string</span>>
str_res = <span style="color: blue;">from</span> res <span style="color: blue;">in</span>
techaltum_student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> res;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//access the element and print in the screen</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">string</span>
final_res <span style="color: blue;">in</span> str_res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//show data with some spaces</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
Response.Write(final_res+<span style="color: #a31515;">" "</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The output of this code as follows:-<o:p></o:p></div>
<div class="MsoNormal">
<v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape alt="Description: C:\Users\Avi\Desktop\Linq1-1.png" id="Picture_x0020_1" o:spid="_x0000_i1025" style="height: 71.25pt; mso-wrap-style: square; visibility: visible; width: 210.75pt;" type="#_x0000_t75">
<v:imagedata o:title="Linq1-1" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape><o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRXKpu_vAMxqVoWS1WaSj_wHHgkfNmJOCc0gLwki2_ht0i8rBmKHe8UAj371HONhkALez24l2oEfkTrg_z58t6DC6g5sXbmY7nXjoFUOTic742WFwMdp2ktvrAyQuvQfRJTV8tVgpaxqw/s1600/Linq1-1.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="135" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgRXKpu_vAMxqVoWS1WaSj_wHHgkfNmJOCc0gLwki2_ht0i8rBmKHe8UAj371HONhkALez24l2oEfkTrg_z58t6DC6g5sXbmY7nXjoFUOTic742WFwMdp2ktvrAyQuvQfRJTV8tVgpaxqw/s400/Linq1-1.png" width="400" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Figure1<o:p></o:p></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;"><br /></span></u></b></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;">Use of Where Clause in Query<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We can also filter data using where clause. Some queries and
answer as follows:-<o:p></o:p></div>
<div class="MsoNormal">
Show the names which
length are 4 then we will write the query as follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IEnumerable</span><span style="font-family: Consolas; font-size: 9.5pt;"><<span style="color: blue;">string</span>>
str_res = <span style="color: blue;">from</span> res <span style="color: blue;">in</span>
techaltum_student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">where</span> res.Length==4<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> res;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Show the name which has the word “sh”<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IEnumerable</span><span style="font-family: Consolas; font-size: 9.5pt;"><<span style="color: blue;">string</span>>
str_res = <span style="color: blue;">from</span> res <span style="color: blue;">in</span>
techaltum_student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">where</span> res.Contains(<span style="color: #a31515;">"sh"</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> res;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;">Use of order by in Query<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
If we want to sort the data then we use the order by in the
query as follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IEnumerable</span><span style="font-family: Consolas; font-size: 9.5pt;"><<span style="color: blue;">string</span>>
str_res = <span style="color: blue;">from</span> res <span style="color: blue;">in</span>
techaltum_student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">where</span> res.Contains(<span style="color: #a31515;">"sh"</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">orderby</span> res<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> res;<o:p></o:p></span></div>
<div class="MsoNormal">
by default it will sort in ascending order.<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
If we want to sort in descending order then we will write
the query as follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IEnumerable</span><span style="font-family: Consolas; font-size: 9.5pt;"><<span style="color: blue;">string</span>>
str_res = <span style="color: blue;">from</span> res <span style="color: blue;">in</span>
techaltum_student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">where</span> res.Contains(<span style="color: #a31515;">"sh"</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">orderby</span>
res <span style="color: blue;">descending</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> res;<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<b><u><span style="font-size: 16.0pt; line-height: 115%;">Customization of output<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We can also customize the output using query in LINQ.<o:p></o:p></div>
<div class="MsoNormal">
<b><u><br /></u></b></div>
<div class="MsoNormal">
<b><u>For example<o:p></o:p></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
If you want to show the data in upper case then we customize
the output as follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;"><br /></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: #2b91af; font-family: Consolas; font-size: 9.5pt;">IEnumerable</span><span style="font-family: Consolas; font-size: 9.5pt;"><<span style="color: blue;">string</span>>
str_res = <span style="color: blue;">from</span> res <span style="color: blue;">in</span>
techaltum_student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">where</span> res.Contains(<span style="color: #a31515;">"sh"</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">orderby</span> res <span style="color: blue;">descending</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> res.ToUpper();<o:p></o:p></span></div>
<div class="MsoNormal">
Show data in Gridview<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
We can also show this data in gridview. The code is as
follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> : System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//declare the array</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">string</span>[] techaltum_student = <span style="color: blue;">new</span>
<span style="color: blue;">string</span>[] { <span style="color: #a31515;">"isha"</span>,
<span style="color: #a31515;">"avinash"</span>, <span style="color: #a31515;">"guddu"</span>, <span style="color: #a31515;">"neha
sharma"</span> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//quey using LINQ syntax</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">IEnumerable</span><<span style="color: blue;">string</span>>
str_res = <span style="color: blue;">from</span> res <span style="color: blue;">in</span>
techaltum_student<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">where</span> res.Contains(<span style="color: #a31515;">"sh"</span>)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">orderby</span> res <span style="color: blue;">descending</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> res.ToUpper();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> GridView1.DataSource = str_res;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
GridView1.DataBind();<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br />
<br />
<div class="MsoNormal">
<b><u><span style="font-size: 18.0pt; line-height: 115%;">Let’s take another example<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now implement LINQ on user defined data type. Create class
and add some variable in it. I created the class name TechAltum and add some
variable in it which is as follows:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: grey; font-family: Consolas; font-size: 9.5pt;">///</span><span style="color: green; font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;"><summary></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: grey; font-family: Consolas; font-size: 9.5pt;">///</span><span style="color: green; font-family: Consolas; font-size: 9.5pt;"> Summary description for TechAltum</span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: grey; font-family: Consolas; font-size: 9.5pt;">///</span><span style="color: green; font-family: Consolas; font-size: 9.5pt;"> </span><span style="color: grey; font-family: Consolas; font-size: 9.5pt;"></summary></span><span style="font-family: Consolas; font-size: 9.5pt;"><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">class</span> <span style="color: #2b91af;">TechAltum</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">int</span> stu_id;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
stu_name;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">public</span> <span style="color: blue;">string</span>
stu_course;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
Now create list of type TechAltum data type and add some objects
in it which is as follows and make query using LINQ which is as follow:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> :
System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//creat list and add some object</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">TechAltum</span>>
data = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">TechAltum</span>>() { <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=1, stu_name=<span style="color: #a31515;">"Isha"</span>,
stu_course=<span style="color: #a31515;">"asp.net"</span>}, <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=2, stu_name=<span style="color: #a31515;">"avinash"</span>,
stu_course=<span style="color: #a31515;">"Web Designing"</span>},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=3, stu_name=<span style="color: #a31515;">"Rahul"</span>,
stu_course=<span style="color: #a31515;">"asp.net"</span>}, <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=4, stu_name=<span style="color: #a31515;">"meena"</span>,
stu_course=<span style="color: #a31515;">"oracle"</span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//as we know linq return in IEnumerable so i carried data
in IEnumerable of type TechAltum</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">IEnumerable</span><<span style="color: #2b91af;">TechAltum</span>>
res = <span style="color: blue;">from</span> final_Res <span style="color: blue;">in</span>
data<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">where</span> final_Res.stu_id > 2 &&
final_Res.stu_course == <span style="color: #a31515;">"asp.net"</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">select</span> final_Res;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">TechAltum</span>
ta <span style="color: blue;">in</span> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
Response.Write(<span style="color: #a31515;">"Student Id="</span>
+ ta.stu_id + <span style="color: #a31515;">" Student Name="</span> +
ta.stu_name + <span style="color: #a31515;">" Student Course="</span> +
ta.stu_course);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The output of this code is as follows:-<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvP25FVBi-twGKpJGme6Ww7SCUosjqcrXrDzWslxFV3k6wybS_-AvBQ4b8ENGRhVLCnJ6mBhnmXYubuHiGRlenF89wb1lAJ44cfIOVkNqo7ZR9p66cNs1HLTwY9A8Sal2EfsX44hai0ww/s1600/Linq+1-2.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="182" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhvP25FVBi-twGKpJGme6Ww7SCUosjqcrXrDzWslxFV3k6wybS_-AvBQ4b8ENGRhVLCnJ6mBhnmXYubuHiGRlenF89wb1lAJ44cfIOVkNqo7ZR9p66cNs1HLTwY9A8Sal2EfsX44hai0ww/s640/Linq+1-2.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
<v:shapetype coordsize="21600,21600" filled="f" id="_x0000_t75" o:preferrelative="t" o:spt="75" path="m@4@5l@4@11@9@11@9@5xe" stroked="f">
<v:stroke joinstyle="miter">
<v:formulas>
<v:f eqn="if lineDrawn pixelLineWidth 0">
<v:f eqn="sum @0 1 0">
<v:f eqn="sum 0 0 @1">
<v:f eqn="prod @2 1 2">
<v:f eqn="prod @3 21600 pixelWidth">
<v:f eqn="prod @3 21600 pixelHeight">
<v:f eqn="sum @0 0 1">
<v:f eqn="prod @6 1 2">
<v:f eqn="prod @7 21600 pixelWidth">
<v:f eqn="sum @8 21600 0">
<v:f eqn="prod @7 21600 pixelHeight">
<v:f eqn="sum @10 21600 0">
</v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas>
<v:path gradientshapeok="t" o:connecttype="rect" o:extrusionok="f">
<o:lock aspectratio="t" v:ext="edit">
</o:lock></v:path></v:stroke></v:shapetype><v:shape alt="Description: C:\Users\Avi\Desktop\Linq 1-2.png" id="Picture_x0020_2" o:spid="_x0000_i1025" style="height: 89.25pt; mso-wrap-style: square; visibility: visible; width: 313.5pt;" type="#_x0000_t75">
<v:imagedata o:title="Linq 1-2" src="file:///C:\Users\Avi\AppData\Local\Temp\msohtmlclip1\01\clip_image001.png">
</v:imagedata></v:shape><o:p></o:p></div>
<div class="MsoNormal">
Figure 2<o:p></o:p><br />
<br />
<br />
<div class="MsoNormal">
<b><u><span style="font-size: 14.0pt; line-height: 115%;">Introducing new data Type VAR in LINQ<o:p></o:p></span></u></b></div>
<div class="MsoNormal">
Var is data type in C# which holds the anonymous data. When you
do not know the return type we can hold data in var. the declaration and
definition of var type will be declare in the same line. <o:p></o:p></div>
<div class="MsoNormal">
For example<o:p></o:p></div>
<div class="MsoNormal">
Var x;<o:p></o:p></div>
<div class="MsoNormal">
X=10;<o:p></o:p></div>
<div class="MsoNormal">
That will be wrong syntax in case of var.<o:p></o:p></div>
<div class="MsoNormal">
Var x=10;<o:p></o:p></div>
<div class="MsoNormal">
It will be the correct syntax.<o:p></o:p></div>
<div class="MsoNormal">
Let’s perform the grouping the last example according to the
course then we will use the code as follows with var data type:-<o:p></o:p></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Linq;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Web.UI.WebControls;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">using</span><span style="font-family: Consolas; font-size: 9.5pt;"> System.Collections.Generic;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="color: blue; font-family: Consolas; font-size: 9.5pt;">public</span><span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">partial</span> <span style="color: blue;">class</span> <span style="color: #2b91af;">_Default</span> :
System.Web.UI.<span style="color: #2b91af;">Page</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">{<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">protected</span> <span style="color: blue;">void</span>
Page_Load(<span style="color: blue;">object</span> sender, <span style="color: #2b91af;">EventArgs</span> e)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//creat list and add some object</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">TechAltum</span>>
data = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">TechAltum</span>>() { <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=1, stu_name=<span style="color: #a31515;">"Isha"</span>,
stu_course=<span style="color: #a31515;">"asp.net"</span>}, <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=2, stu_name=<span style="color: #a31515;">"avinash"</span>,
stu_course=<span style="color: #a31515;">"Web Designing"</span>},<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=3, stu_name=<span style="color: #a31515;">"Rahul"</span>,
stu_course=<span style="color: #a31515;">"asp.net"</span>}, <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">new</span> <span style="color: #2b91af;">TechAltum</span>{
stu_id=4, stu_name=<span style="color: #a31515;">"meena"</span>,
stu_course=<span style="color: #a31515;">"oracle"</span>}<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> };<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//take the var data type </span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">var</span> res = <span style="color: blue;">from</span>
final_Res <span style="color: blue;">in</span> data<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: blue;">group</span> final_Res <span style="color: blue;">by</span>
final_Res.stu_course;<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> course <span style="color: blue;">in</span> res)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: green;">//preint the key on which we grouped data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
Response.Write(<span style="color: #a31515;">"<html></br></br></html>"</span>+course.Key
+ <span style="color: #a31515;">"<html></br></br></html>"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> <span style="color: blue;">foreach</span> (<span style="color: blue;">var</span> stu_data
<span style="color: blue;">in</span> course)<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> {<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
<span style="color: green;">//show data</span><o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">
Response.Write(<span style="color: #a31515;">"Student Id="</span>
+ stu_data.stu_id + <span style="color: #a31515;">" Student Name="</span>
+ stu_data.stu_name + <span style="color: #a31515;">" Student Course="</span>
+ stu_data.stu_course+<span style="color: #a31515;">"<html></br></html>"</span>);<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<br /></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;"> }<o:p></o:p></span></div>
<div class="MsoNormal" style="margin-bottom: 0.0001pt;">
<span style="font-family: Consolas; font-size: 9.5pt;">}<o:p></o:p></span></div>
<div class="MsoNormal">
<br /></div>
<div class="MsoNormal">
The output of this code as follows:-<o:p></o:p></div>
<div class="MsoNormal">
<br /></div>
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3WUMaWmd1pThF_rpRkEzdISK2wRxLfmGYg36W3ve8CXTdzST2NiVPUaf00sTuh56lGFCyKlR5wydAPSnbyT_pSM9JLaDNXhblhgvAttXnxG638qcYTkAocFTZ4CZKgNb8GFP8aQFfwgg/s1600/Linq+1-3.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="554" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi3WUMaWmd1pThF_rpRkEzdISK2wRxLfmGYg36W3ve8CXTdzST2NiVPUaf00sTuh56lGFCyKlR5wydAPSnbyT_pSM9JLaDNXhblhgvAttXnxG638qcYTkAocFTZ4CZKgNb8GFP8aQFfwgg/s640/Linq+1-3.png" width="640" /></a></div>
<div class="MsoNormal">
<br /></div>
</div>
</div>
<br />
Figure 4<br />
<br />
Hope you enjoyed the article<br />
<span class="GingerNoCheckEnd"></span><span class="GingerNoCheckEnd"></span><span class="GingerNoCheckEnd"></span></div>
Anonymoushttp://www.blogger.com/profile/08203366298489829818noreply@blogger.com2