<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2enclosuresfull.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:atom="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:blogger="http://schemas.google.com/blogger/2008" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr="http://purl.org/syndication/thread/1.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"><channel><atom:id>tag:blogger.com,1999:blog-1194836729866470946</atom:id><lastBuildDate>Thu, 23 May 2013 02:36:53 +0000</lastBuildDate><category>LINQ</category><category>Visual Studio</category><category>Bulk Insert</category><category>reflection</category><category>Dictionary</category><category>Duplex</category><category>foreach</category><category>REST</category><category>OpenXML</category><category>Expression Tree</category><category>Stored Procedure</category><category>Image</category><category>SilverLight</category><category>Asp.Net</category><category>TypeDataSet</category><category>Sql Server</category><category>Business Application</category><category>collection</category><category>Cross Domain</category><category>Beginner</category><category>Ajax</category><category>JAVA SCRIPT / JQUERY</category><category>Linq to XML</category><category>Testing</category><category>string</category><category>c#</category><category>split</category><category>DateTime</category><category>Exception</category><category>RAD Control</category><category>Intermediate</category><category>WCF</category><category>CSS3</category><category>Database</category><category>Lazy initialization</category><category>HTML / CSS</category><category>Linq to SQL</category><category>Certificate</category><category>Debugging</category><category>.net</category><category>Entity Framework</category><category>HTML5</category><title>Pranay Rana</title><description /><link>http://pranayamr.blogspot.com/</link><managingEditor>noreply@blogger.com (pranay rana)</managingEditor><generator>Blogger</generator><openSearch:totalResults>124</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/GmindSolution" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="gmindsolution" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><media:copyright>Pranay Rana @2010 Gmind Solution</media:copyright><media:thumbnail url="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1326.snc4/161669_100000480841158_3237723_n.jpg" /><media:keywords>net,wcf,linq,sql,jquery,javascript,c</media:keywords><media:category scheme="http://www.itunes.com/dtds/podcast-1.0.dtd">Technology/Software How-To</media:category><itunes:owner><itunes:email>pranayamr@gmail.com</itunes:email><itunes:name>Pranay Rana</itunes:name></itunes:owner><itunes:author>Pranay Rana</itunes:author><itunes:explicit>no</itunes:explicit><itunes:image href="http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs1326.snc4/161669_100000480841158_3237723_n.jpg" /><itunes:keywords>net,wcf,linq,sql,jquery,javascript,c</itunes:keywords><itunes:subtitle>Gmind Solution</itunes:subtitle><itunes:category text="Technology"><itunes:category text="Software How-To" /></itunes:category><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-5222601892455435771</guid><pubDate>Sat, 16 Mar 2013 13:29:00 +0000</pubDate><atom:updated>2013-03-16T09:57:00.095-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">JAVA SCRIPT / JQUERY</category><category domain="http://www.blogger.com/atom/ns#">HTML5</category><title>Store data locally with HTML5 Web Storage</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
Now new version of HTML5 having number of new API one of the is Storage API, which allow you to store data of use locally. Here in following post I am going to describe Storage API.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Cookies vs. Storage&lt;/b&gt;&lt;br /&gt;
In previous version of HTML allows to store data locally with the help of Cookies but the&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&amp;nbsp;issue with the cookies is its not allow to big object and which can be easily done. Storage allows  5M (most browsers) or 10M (IE) of memory at disposal.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Another problem is cookies get sent to server with each HTTP request which in term increases traffic.
&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Storage&lt;/b&gt; &lt;br /&gt;
Now lets start using the store in application
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;if(typeof(Storage)!=="undefined")
{
  alert("storage is supported and you can store data in it"); 
}
else
{
 alert("Get new version of browser or use browser which support storage");
}
&lt;/pre&gt;
So here in above as you can see, first line of code check weather browser supports/have Storage object. It's good to check because most of the older browser is not supporting and as its new feature its mostly supported in new browsers.&lt;br /&gt;
&lt;br /&gt;
After doing check for Storage support decide either you want to store data for given session only or want to store data which available even after session is over and when user come back. 
&lt;br /&gt;
So there are two type of object which is explained below
&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;sessionStorage is used to store within the browser tab or window session. so it allows to store data in a single web page session.
&lt;/li&gt;
&lt;li&gt;
localStorage is used to kept even between browser sessions. so it allows to access data after the browser is closed and reopened again, and also instantly between tabs and windows.
&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Note : &lt;/b&gt;Storage data created by one browser is not avaible in other browser. for example created in IE is not available in FireFox.&lt;br /&gt;
&lt;br /&gt;
Following is the way you can use the localStorage and sessionStorage in your application.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//sessionStorage &lt;/pre&gt;
&lt;pre class="brush: csharp"&gt;//set and get object 
sessionStorage.setItem('myKey', 'myValue');
var myVar = sessionStorage.getItem('myKey');
//another way to set and get 
sessionStorage.myKey = 'myValue';
var myVar = sessionStorage.myKey;

//remove item
sessionStorage.removeItem('myKey');

//clear storage 
sessionStorage.clear();
&lt;/pre&gt;
&lt;pre class="brush: csharp"&gt;
//localStorage 
//set and get object 
localStorage.setItem('myKey', 'myValue');
var myVar = localStorage.getItem('myKey');
//another way to set and get 
localStorage.myKey = 'myValue';
var myVar = localStorage.myKey;

//remove item
localStorage.removeItem('myKey');

//clear storage 
localStorage.clear();
&lt;/pre&gt;
as in the above code both of the object support same set of methods to store and retrieve data.&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;setItem - allows to set value.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;getItem - allows to get value.&lt;/li&gt;
&lt;li&gt;removeItem - allows to remove object from storage. &lt;b&gt;Note:&lt;/b&gt; if it used like removeItem(), it removes all stored object , so be careful when removing -to remove specific object use removeItem("myKey").&amp;nbsp; &lt;/li&gt;
&lt;li&gt;clear - clear storage i.e. clear all stored data.&lt;/li&gt;
&lt;/ul&gt;
and as you can see storage store data in key value pair.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
Web Storage simplify the storing of object in client and also have advantage over cookies, but its always good to not store sensitive information in the client side storage as storage is not provide that much security.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Thanks for reading and do post comment if you like it or something is missing or wrong.&lt;/b&gt; &lt;/div&gt;
</description><link>http://pranayamr.blogspot.com/2013/03/store-data-locally-with-html5-web.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>23</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-4171877979465324481</guid><pubDate>Thu, 14 Mar 2013 07:09:00 +0000</pubDate><atom:updated>2013-03-14T12:11:09.132-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Linq to XML</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Object to XML using LINQ or XmlSerializer</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In Following post I am going show you how easily you can convert you object in the XML string, because sometime there is need of pass object and XML from one function to another and also convert XML string back to object. But As title suggest here I just going to discuss the conversion of object to XML string. 
&lt;br /&gt;
&lt;br /&gt;
Following two way to achieve this task of converting Object to XML. 
&lt;br /&gt;
&lt;br /&gt;
Before we start Below is class structure which object need to be convert in XML string.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public class Product
    {
        public string Name { get; set; }
        public int Code { get; set; }
        public List&amp;lt;productType&amp;gt; types {get; set;}
    }

    public class productType
    {
        public string type {get; set;}
    }
&lt;/pre&gt;
As you can see in structure Product is class and it's having list of producttype in it.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Way 1 : Linq To XML
&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt; List&amp;lt;productType&amp;gt; typ = new List&amp;lt;productType&amp;gt;();
            typ.Add((new productType() { type="Type1"}));
            typ.Add((new productType() { type = "Type2" }));
            typ.Add((new productType() { type = "Type3" }));

            Product[] products = { new Product { Name = "apple", Code = 9,types=typ }, 
                       new Product { Name = "orange", Code = 4,types=typ   }, 
                       new Product { Name = "apple", Code = 9 ,types=typ}, 
                       new Product { Name = "lemon", Code = 9,types=typ } };
&lt;/pre&gt;
Above code is creating array of product which contains the object of product. Over all its initializing the product array object.Now to convert this in the XML using Linq following is code 
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;            XElement _customers = new XElement("Products",
                       from c in products
                       orderby c.Code 
                        select new XElement("product",
                            new XElement("Code", c.Code),
                            new XElement("Name", c.Name),
                            new XElement("Types", (from x in c.types
                                                  orderby x.type//descending 
                            select new XElement("Type",x.type)) 
                        ))
                  );

            Console.WriteLine(_customers.ToString());
&lt;/pre&gt;
As you see in above code its converting the each property of object in XMLElement by using method of Linq To XML which is XElement. You can modify structure as per you needs here is more on &lt;a href="http://msdn.microsoft.com/en-us/library/bb387098.aspx"&gt;Linq to XML&lt;/a&gt;

&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;a href="http://2.bp.blogspot.com/-_HIK8197Rl4/UUB-BVUKRPI/AAAAAAAADWw/F4nPTBY2tcw/s1600/object+to+xml.JPG" imageanchor="1"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-_HIK8197Rl4/UUB-BVUKRPI/AAAAAAAADWw/F4nPTBY2tcw/s320/object+to+xml.JPG" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Way 2 : Make use of XmlSerializer 
&lt;/b&gt;&lt;br /&gt;
You can easily convert the object in XML string by using Serializer as shown below. This process called as object serialization.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;            XmlSerializer xser = new XmlSerializer(products.GetType());
            xser.Serialize(Console.Out, products);
            Console.ReadLine();
&lt;/pre&gt;
As you see there just two line of code need to conversion. There is no need to write more amount of the code like Linq To XML, But if you want to control structure of the generated XML you need to decorate your class with XmlAttributes. Read more about this &lt;a href="http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx"&gt;XmlSerializer&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;a href="http://4.bp.blogspot.com/-GM8a-0uBZbQ/UUFxSQCmU-I/AAAAAAAADXA/YXr1WUfRxN0/s1600/xml+object.JPG" imageanchor="1"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-GM8a-0uBZbQ/UUFxSQCmU-I/AAAAAAAADXA/YXr1WUfRxN0/s320/xml+object.JPG" /&gt;&lt;/a&gt;

&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Comparison between both the ways&lt;/b&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Big difference between both is way XML string is generated. That you can easily figure out form the Output of both the way.&lt;/li&gt;
&lt;li&gt;&lt;i&gt;XmlSerializer&lt;/i&gt;&amp;nbsp;provide more control on XML than than the Lin To XML.&lt;/li&gt;
&lt;li&gt;As stated with Linq to Xml you need to write down more amount of code to structure the XML string which is very easy with &lt;i&gt;XmlSerializer&lt;/i&gt;. But if you dont want the default structure generated by &lt;i&gt;XmlSerializer &lt;/i&gt;you need to use &lt;i&gt;XmlAttributes &lt;/i&gt;for each property. 
with attribute class will be&lt;/li&gt;
&lt;/ul&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt; public class Product
    {
        [XmlElement("Product Name")]
        public string Name { get; set; }
        [XmlElement("Code")]
        public int Code { get; set; }
        [XmlElement("Types")]
        public List&lt;producttye&gt; types {get; set;}
    }
&lt;/producttye&gt;&lt;/pre&gt;
But you can easily do this in Linq to XML.&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;&amp;nbsp;When you dont want to include some property in XML string. you just need to skip that property like this.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre class="brush: csharp"&gt;XElement _customers = new XElement("Products",
                       from c in products
                       orderby c.Code //descending 
                        select new XElement("product",
                            //new XElement("Code", c.Code),
                            new XElement("Name", c.Name),
                            new XElement("Types", (from x in c.types
                                                  orderby x.type//descending 
                            select new XElement("Type",x.type)) 
                        ))
                  );
&lt;/pre&gt;
in linq to xml you just need to remove it here i just commented Code so there is no element for Code.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://4.bp.blogspot.com/-t2lWYoJxpsE/UUF0n09GJcI/AAAAAAAADXQ/DBNQbs8xJQg/s1600/linq+to+xml+out.JPG" imageanchor="1" style="clear: left; float: left; margin-bottom: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://4.bp.blogspot.com/-t2lWYoJxpsE/UUF0n09GJcI/AAAAAAAADXQ/DBNQbs8xJQg/s1600/linq+to+xml+out.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For XmlSerializer you need to put attribute called&lt;i&gt; [Obsolete]&lt;/i&gt; on top of property.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;        public string Name { get; set; }
        [Obsolete]
        public int Code { get; set; }
        public List&lt;producttye&gt; types {get; set;}&lt;/producttye&gt;&lt;/pre&gt;
&lt;br /&gt;
&lt;pre&gt;&lt;producttye&gt;&lt;a href="http://2.bp.blogspot.com/-UBj5dLayQ7s/UUF0tEpGP8I/AAAAAAAADXY/ymR-xcLcm-w/s1600/xmlser+output.JPG" imageanchor="1" style="font-family: 'Times New Roman'; margin-left: 1em; margin-right: 1em; text-align: center; white-space: normal;"&gt;&lt;img border="0" src="http://2.bp.blogspot.com/-UBj5dLayQ7s/UUF0tEpGP8I/AAAAAAAADXY/ymR-xcLcm-w/s1600/xmlser+output.JPG" /&gt;&lt;/a&gt;&lt;/producttye&gt;&lt;/pre&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Another Difference is Linq TO XML is faster than XmlSerializer which you can easy see by running the code its because XmlSerializer is Serializing object which might be using reflection and other metadata information about the object.&lt;/li&gt;
&lt;/ul&gt;
&lt;b&gt;Conclusion
&lt;/b&gt;&lt;br /&gt;
You can use one of the way as per your need. But if you just want to generate XML than its better to go for Linq to XML and if there is serialization/ de-serialization&amp;nbsp;required&amp;nbsp;than go for&amp;nbsp;XmlSerializer&amp;nbsp;.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Provide comments if you find more difference and there is thing change require in above. Thanks for reading.&lt;/b&gt;&lt;/div&gt;
&lt;br /&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2013/03/object-to-xml-using-linq-or.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://2.bp.blogspot.com/-_HIK8197Rl4/UUB-BVUKRPI/AAAAAAAADWw/F4nPTBY2tcw/s72-c/object+to+xml.JPG" height="72" width="72" /><thr:total>7</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-956722316594408216</guid><pubDate>Mon, 28 Jan 2013 19:59:00 +0000</pubDate><atom:updated>2013-01-29T00:30:07.400-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HTML / CSS</category><category domain="http://www.blogger.com/atom/ns#">CSS3</category><title>CSS Selector</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post is about CSS selector and how it woks. Following is&amp;nbsp;explanation&amp;nbsp;of most of the selector that is used in CSS.&lt;br /&gt;
&lt;br /&gt;
In the following first is css example and than html code on which it will work, so to try by yourself create html page and put the css as well as related Html and see the result. In most of the select I provided demo link where you can visit and see the result.&lt;br /&gt;
&lt;br /&gt;
In below post you might find some new CSS selector that are the part of new CSS3. All of the below examples and demo tried by me on latest Chrome version.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;.Class&lt;/b&gt; -: Select all the element with given class name.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;.MyIntro
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use
&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div class="MyIntro"&amp;gt;
&amp;lt;p&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;&lt;/pre&gt;
&lt;hr /&gt;
&lt;b&gt;#id -:&lt;/b&gt; Select all the element with given id name.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt; #MyIntro
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div id="MyIntro"&amp;gt;
&amp;lt;p&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
Point to Note :
You can have more than one element having same classname in HTML page but you can have only one element with the ID.&lt;br /&gt;
&lt;hr /&gt;
&lt;b&gt;HTMLElement&lt;/b&gt; - Select all the html element which name is given.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt; p
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;
&amp;lt;p&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
&lt;hr /&gt;
&lt;b&gt;HtmlElement HtmlElemnt &lt;/b&gt;- Select all the html element which are in html element.
&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;div p
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div &amp;gt;
&amp;lt;p&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
&amp;lt;Span&amp;gt;
 &amp;lt;p&amp;gt; data &amp;lt;/p&amp;gt;
&amp;lt;/Span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&lt;/pre&gt;
in this example all p element inside div get highlighted with read color, but p element outside div doesnt get affected.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/2/"&gt;Demo&lt;/a&gt;&amp;nbsp;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;HtmlElement &amp;gt; HtmlElemnt&lt;/b&gt; - Select all the html element which are child of html element.
&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;div &amp;gt; p
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div &amp;gt;
&amp;lt;p&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
&amp;lt;Span&amp;gt;
 &amp;lt;p&amp;gt; data &amp;lt;/p&amp;gt;
&amp;lt;/Span&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&lt;/pre&gt;
in this example all p element which are child of div get highlighted with read color, but p element which are not child of div doesnt get affected.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/1/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&amp;nbsp;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;HtmlElement + HtmlElemnt&lt;/b&gt; - Select all the html element which are immediate after html element.
&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;div + p
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div &amp;gt;
&amp;lt;p&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt; data &amp;lt;/p&amp;gt;
&lt;/pre&gt;
in this example p element which is immediate after div get&amp;nbsp;highlighted&amp;nbsp;with read color, in this example "I am working as Soft Engg." this text get highlighted.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;HtmlElement ~ HtmlElemnt&lt;/b&gt; - Select all the html element which are precedes html element.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;div ~ p
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div &amp;gt;
&amp;lt;p&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
    &amp;lt;span&amp;gt;
        &amp;lt;p&amp;gt; data &amp;lt;/p&amp;gt;
  &amp;lt;/span&amp;gt; 
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;p&amp;gt;My Demo Page.&amp;lt;/p&amp;gt;
&lt;/pre&gt;
in this example p element which is precedes div get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with read color, in this example "I am working as Soft Engg." and "My Demo Page." text get highlighted.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/3/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;[attribute]&lt;/b&gt; - Select all the html element which is having attribute.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[data-name]
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div &amp;gt;
&amp;lt;p data-name="pranay"&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
    &amp;lt;span&amp;gt;
        &amp;lt;p&amp;gt; data &amp;lt;/p&amp;gt;
  &amp;lt;/span&amp;gt; 
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;p data-name="demo"&amp;gt;My Demo Page.&amp;lt;/p&amp;gt;
&lt;/pre&gt;
in this example any element which is having attribute "data-name"div get&amp;nbsp;highlighted&amp;nbsp;with red color, in this example "My name is Pranay Rana." and "My Demo Page." text get highlighted.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/5/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;[attribute = data]&lt;/b&gt; - Select all the html element which is having attribute value equal to data.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[data-name = 'demo']
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div &amp;gt;
&amp;lt;p data-name="pranay"&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
    &amp;lt;span&amp;gt;
        &amp;lt;p&amp;gt; data &amp;lt;/p&amp;gt;
  &amp;lt;/span&amp;gt; 
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;p data-name="demo"&amp;gt;My Demo Page.&amp;lt;/p&amp;gt;
&lt;/pre&gt;
in this example any element which is having attribute "data-name" and value = "demo" get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, in this example "My Demo Page." text get highlighted.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/17/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;[attribute ^= data]&lt;/b&gt; - Select all the html element where attribute value begins with data.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[data-name ^= 'pra']
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;div&gt;
So with the above html when apply this "My name is Pranay Rana." &amp;nbsp;text is get highlighted because its "data-name" attribute value begining with "pra".&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/20/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;[attribute $= data]&lt;/b&gt; - Select all the html element where attribute value end with data.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[data-name ^= 'pra']
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;div&gt;
So with the above html when apply this "My name is Pranay Rana." &amp;nbsp;text is get highlighted because its "data-name" attribute value ending with "nay".&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/22/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;[attribute *= data]&lt;/b&gt; - Select all the html element where attribute value contains data.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[data-name *= 'rana']
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;div&gt;
So with the above html when apply this "My name is Pranay Rana." &amp;nbsp;text is get highlighted because its "data-name" attribute value contains "rana".&lt;/div&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/23/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;[attribute ~= data]&lt;/b&gt; - Select all the html element where attribute value contains word data.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[data-name ~= 'page']
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div &amp;gt;
&amp;lt;p data-name="pranay_page"&amp;gt;My name is Pranay Rana.&amp;lt;/p&amp;gt;
    &amp;lt;span&amp;gt;
        &amp;lt;p&amp;gt; data &amp;lt;/p&amp;gt;
  &amp;lt;/span&amp;gt; 
&amp;lt;/div&amp;gt;
&amp;lt;p&amp;gt;I am working as Soft Engg.&amp;lt;/p&amp;gt;
&amp;lt;p data-name="demo page"&amp;gt;My Demo Page.&amp;lt;/p&amp;gt;
&lt;/pre&gt;
in this example any element where attribute "data-name" &amp;nbsp;value contains word = "page" get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, in this example "My Demo Page." text get highlighted&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/24/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:first-child &lt;/b&gt;- Select first element (first child) of parent.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;li:forst-child
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;item1&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item2&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item3&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item4&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/pre&gt;
in this example "item1" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/29/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:last-child &lt;/b&gt;- Select last element (last child) of parent.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;li:last-child
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;item1&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item2&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item3&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item4&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/pre&gt;
in this example "item4" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/28/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:nth-child(n) &lt;/b&gt;- Select all each element which n the child of parent.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;li:nth-child(2)
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;item1&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item2&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item3&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item4&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/pre&gt;
in this example "second li" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, in this example "item2" text get highlighted&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/26/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:nth-child(n)&lt;/b&gt; - Select all each element which last n the child&amp;nbsp;of parent&amp;nbsp;counting from bottom .&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;li:nth-child(2)
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;item1&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item2&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item3&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item4&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
&lt;/pre&gt;
in this example "second last li" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, in this example "item3" text get highlighted&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/27/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:only-child &lt;/b&gt;- Select child element which only child&amp;nbsp;of parent .&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;p:only-child
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt; 
&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 4&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
in this example "paraghaph 1" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color,which is only child of div element.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/35/"&gt;&lt;b&gt;Demo&lt;/b&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:first-of-type &lt;/b&gt;- Select first element of given type which is first comes under parent element.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;p:first-of-type
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
in this example "paragraph 1" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/30/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:last-of-type &lt;/b&gt;- Select last element of given type which is last comes under parent element.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;p:last-of-type
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/pre&gt;
in this example "paragraph 1" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, that means here "pragraph 1" is first element of type p under div.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/31/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:nth-of-type(n) &lt;/b&gt;- Select nth element of given type which comes at nth place under parent element.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;p:nth-of-type(2)
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 4&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;  
&lt;/pre&gt;
in this example "paragraph 2" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, that means here "pragraph 2" is 2th element of type p under div.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/32/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:nth-last-of-type(n) &lt;/b&gt;- Select nth last element of given type which comes at nth place under parent element from last.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;p:nth-last-of-type(2)
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 4&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;  
&lt;/pre&gt;
in this example "paragraph 3" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, that means here "pragraph 3" is last element of type p under div from last.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/33/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:only-of-type &lt;/b&gt;- Select only element of given type which comes under parent element.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;p:only-of-type
{
  font:15px arial,sans-serif;
  color:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt; 
&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 4&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;  
&lt;/pre&gt;
in this example "paragraph 1" element get&amp;nbsp;highlighted&amp;nbsp;&amp;nbsp;with red color, because p is only element of given type.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/34/"&gt;Demo&lt;/a&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:empty &lt;/b&gt;- Select element which is empty i.e. donent have any child.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;div:empty
{
  width:100px;
height:20px;
background:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt; 
&amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 4&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;  
&lt;/pre&gt;
in this highlight all text in the document with red color.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/36/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;::selection - &lt;/b&gt;highlight the text with the color selected.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;::selection
{
  background:green;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;div&amp;gt;&amp;nbsp;&amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt; &amp;lt;/div&amp;gt; 
   &amp;lt;div&amp;gt;
    &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
    &amp;lt;p&amp;gt; pragraph 4&amp;lt;/p&amp;gt;
&amp;lt;/div&amp;gt;    
&lt;/pre&gt;
in this highlight all text with green which get select in document.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/37/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:not(HTMLElement)&lt;/b&gt; - it not apply the style to the HTMLElement specified.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;:not(span)
{
  font:15px arial,sans-serif;
  color:red;
}
span
{
  color:black;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt; &amp;lt;p&amp;gt; pragraph 1&amp;lt;/p&amp;gt;
 &amp;lt;p&amp;gt; pragraph 2&amp;lt;/p&amp;gt;
 &amp;lt;p&amp;gt; pragraph 3&amp;lt;/p&amp;gt;
 &amp;lt;p&amp;gt; pragraph 4&amp;lt;/p&amp;gt;
 &amp;lt;span&amp;gt; span data&amp;lt;/span&amp;gt;    
&lt;/pre&gt;
in this highlight all text which is in p element i.e. not apply style to span element.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;b&gt;&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/38/"&gt;Demo&lt;/a&gt;&lt;/b&gt;&lt;/h2&gt;
&lt;hr /&gt;
&lt;b&gt;:enable &lt;/b&gt;- select to all enable element.&lt;br /&gt;
&lt;b&gt;:disable &lt;/b&gt;- select to all disable element.&lt;br /&gt;
&lt;i&gt;CSS&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;:input[type="text"]:enabled
{
background:green;
}
input[type="text"]:disabled
{
background:red;
}
&lt;/pre&gt;
&lt;i&gt;Use&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Name: &amp;lt;input type="text" value="Pranay Rana" /&amp;gt;&amp;lt;br&amp;gt;
Country: &amp;lt;input type="text" disabled="disabled" value="India" /&amp;gt;    
&lt;/pre&gt;
here name is get&amp;nbsp;highlighted&amp;nbsp;with red color and country box is get&amp;nbsp;highlighted&amp;nbsp;with green.&lt;br /&gt;
&lt;h2 style="text-align: left;"&gt;
&lt;a style="font-size:15px;" href="http://jsfiddle.net/qCTvE/39/"&gt;&lt;b&gt;Demo&lt;/b&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
Most of the selector are new here those are part of CSS3, I hope that helpful to understand well. I covered most of the CSS selector here but if there is something missing please place comment below regarding it.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Leave comment if you have any query or if you like it. &amp;nbsp;Pelease report if any link is not working or broken.&lt;/b&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2013/01/css-selector.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>49</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-443366823778071507</guid><pubDate>Fri, 25 Jan 2013 20:27:00 +0000</pubDate><atom:updated>2013-01-25T23:08:19.462-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>DistinctBy in Linq (Find Distinct object by Property)</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post I am going to discuss about how to get distinct object using property  of it from collection. Here I am going to show three different way to achieve it easily.&lt;br /&gt;
In this post I am going to discuss about extension method that can do task more than the current Distinct method available in .Net framework.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Distinct method of Linq works as following right now. 
&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public class Product
{
    public string Name { get; set; }
    public int Code { get; set; }
}
&lt;/pre&gt;
Consider that we have product Class which is having Code and Name as property in it.
&lt;br /&gt;
Now Requirement is I have to find out the all product with distinct Code values.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Product[] products = { new Product { Name = "apple", Code = 9 }, 
                       new Product { Name = "orange", Code = 4 }, 
                       new Product { Name = "apple", Code = 10 }, 
                       new Product { Name = "lemon", Code = 9 } };
var lstDistProduct = products.Distinct();
foreach (Product p in list1)
{
     Console.WriteLine(p.Code + " : " + p.Name);
}
&lt;/pre&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-Tv0X_GfUL7Q/UQLWKff0q4I/AAAAAAAADV8/RWlT4GkTRng/s1600/output.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="96" src="http://2.bp.blogspot.com/-Tv0X_GfUL7Q/UQLWKff0q4I/AAAAAAAADV8/RWlT4GkTRng/s400/output.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
It returns all the product event though two product have same Code value. So this doesn't meet requirement of getting object with distinct Code value.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Way 1 : Make use of MoreLinq Library
&lt;/b&gt;&lt;br /&gt;
First way to achieve the requirement is make use of MoreLinq Library, which support function called &lt;i&gt;DistinctBy&lt;/i&gt; in which you can specify the property on which you want to find &lt;i&gt;Distinct &lt;/i&gt;objects.&lt;br /&gt;
Below code is shows the use of the function. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var list1 = products.DistinctBy(x=&amp;gt; x.Code);

foreach (Product p in list1)
{
     Console.WriteLine(p.Code + " : " + p.Name);
}
&lt;/pre&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-gnz1-OzU0_8/UQLXNPgNBzI/AAAAAAAADWM/OgVVTN9-K7A/s1600/output.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="85" src="http://2.bp.blogspot.com/-gnz1-OzU0_8/UQLXNPgNBzI/AAAAAAAADWM/OgVVTN9-K7A/s400/output.jpg" width="398" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
As &amp;nbsp;you can see in output there is only two object get return which actually I want. i.e. distinct value by Code or product.&lt;br /&gt;
If you want to pass more than on property than you can just do like this &lt;i&gt;&amp;nbsp;var list1 = products.DistinctBy(a =&amp;gt; new { a.Name, a.Code });&lt;/i&gt;&lt;br /&gt;
You can read about the MoreLinq and Download this DLL from here :&amp;nbsp;&lt;a href="http://code.google.com/p/morelinq/"&gt;http://code.google.com/p/morelinq/&lt;/a&gt;&amp;nbsp;one more thing about this library also contains number of other function that you can check.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Way 2: Implement Comparable&lt;/b&gt;&lt;br /&gt;
Second way to achieve the same functionality is make use of overload Distinct function which support to have comparator as argument.&lt;br /&gt;
here is MSDN documentation on this :&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/bb338049.aspx"&gt;Enumerable.Distinct&amp;lt;TSource&amp;gt; Method (IEnumerable&amp;lt;TSource&amp;gt;, IEqualityComparer&amp;lt;TSource&amp;gt;)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
So for that I&amp;nbsp;implemented &lt;i&gt;IEqualityComparer &lt;/i&gt;and created new&lt;i&gt;&amp;nbsp;ProductComparare &lt;/i&gt;which you can see in below code.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;   
    class ProductComparare : IEqualityComparer&lt;product&gt;
    {
        private Func&amp;lt;Product, object&amp;gt; _funcDistinct;
        public ProductComparare(Func&amp;lt;Product, object&amp;gt; funcDistinct)
        {
            this._funcDistinct = funcDistinct;
        }

        public bool Equals(Product x, Product y)
        {
            return _funcDistinct(x).Equals(_funcDistinct(y));
        }

        public int GetHashCode(Product obj)
        {
            return this._funcDistinct(obj).GetHashCode();
        }
    }
&lt;/product&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
So In ProductComparare constructor I am passing function as argument, so when I create any object of it I have to pass my project function as argument.&lt;br /&gt;
In Equal method I am comparing object which are returned by my projection function.&lt;br /&gt;
Now following is the way how I used this Comparare implementation to satisfy my requirement.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var list2 = products.Distinct(new ProductComparare( a =&amp;gt; a.Code ));

            foreach (Product p in list2)
            {
                Console.WriteLine(p.Code + " : " + p.Name);
            }
&lt;/pre&gt;
&lt;b&gt;Output

&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-gnz1-OzU0_8/UQLXNPgNBzI/AAAAAAAADWM/OgVVTN9-K7A/s1600/output.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="85" src="http://2.bp.blogspot.com/-gnz1-OzU0_8/UQLXNPgNBzI/AAAAAAAADWM/OgVVTN9-K7A/s400/output.jpg" width="398" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
So this&amp;nbsp;approach&amp;nbsp;also satisfy my requirement easily. I not looked in code of MoreLinq library but I think its also doing like this only. If you want to pass more than on property than you can just do like this&amp;nbsp;&lt;i&gt;&amp;nbsp;var list1 = products.Distinct(a =&amp;gt; new { a.Name, a.Code });.&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Way 3: Easy GroupBy wa&lt;/b&gt;&lt;br /&gt;
The third and most eaisest way to avoide this I did in above like using MoreLine and Comparare implementation is just make use of GroupBy like as below&lt;br /&gt;
&lt;pre class="brush: csharp"&gt; List&amp;lt;Product&amp;gt; list = products
                   .GroupBy(a =&amp;gt; a.Code )
                   .Select(g =&amp;gt; g.First())
                   .ToList();

            foreach (Product p in list)
            {
                Console.WriteLine(p.Code + " : " + p.Name);
            }
&lt;/pre&gt;
In above code I am doing grouping object on basis of property and than in Select function just selecting fist one of the each group will doing work for me.&lt;br /&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-gnz1-OzU0_8/UQLXNPgNBzI/AAAAAAAADWM/OgVVTN9-K7A/s1600/output.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="85" src="http://2.bp.blogspot.com/-gnz1-OzU0_8/UQLXNPgNBzI/AAAAAAAADWM/OgVVTN9-K7A/s400/output.jpg" width="398" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
So this&amp;nbsp;approach&amp;nbsp;also satisfy my requirement easily and output is similar to above two approach. If you want to pass more than on property than you can just do like this&amp;nbsp;&lt;i&gt;&amp;nbsp;&amp;nbsp;.GroupBy(a =&amp;gt; new { a.Name, a.Code }).&lt;/i&gt;&lt;br /&gt;
&lt;br /&gt;
So this one is very easy trick to achieve the functionality that I want without&amp;nbsp;using&amp;nbsp;any thing extra in my code.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
So Above is the way you can achieve Distinct of collection easily by property of object.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Leave comment if you have any query or if you like it.&lt;/b&gt;&lt;/div&gt;
</description><link>http://pranayamr.blogspot.com/2013/01/distinctby-in-linq.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://2.bp.blogspot.com/-Tv0X_GfUL7Q/UQLWKff0q4I/AAAAAAAADV8/RWlT4GkTRng/s72-c/output.jpg" height="72" width="72" /><thr:total>11</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-1785980549765321533</guid><pubDate>Wed, 23 Jan 2013 19:01:00 +0000</pubDate><atom:updated>2013-01-25T15:25:23.561-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">HTML5</category><title>GeoLocation API in HTML5</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
HTML5 have cool feature that is provide gelocation of the user on the fly without using any extra services that we do right now. This feature is supported by Gelocation API which is part of HTML5.&lt;br /&gt;
&lt;br /&gt;
Following is sample Code in JavaScript how it works.
&lt;br /&gt;
&lt;pre  class="brush: csharp"&gt;&amp;lt;button onclick="getGeoLocation()"&amp;gt;Get GeoLocation&amp;lt;/button&amp;gt;
&amp;lt;script&amp;gt;
  function getGeoLocation()
  {
    if (navigator.geolocation)
    {
      navigator.geolocation.getCurrentPosition(showPosition,HandleError);
    }
    else
    {
      alert("Geolocation is not supported by this browser.");
    }
  }
  function showPosition(position)
  {
      alert("Latitude: " + position.coords.latitude + 
               "    Longitude: " + position.coords.longitude); 
  }
&amp;lt;/script&amp;gt;
&lt;/pre&gt;
Code is work in this pattern.
&lt;br /&gt;
&lt;ol style="text-align: left;"&gt;
&lt;li&gt;First when user click on button it calls &lt;i&gt;getGeoLocation&lt;/i&gt;&lt;/li&gt;
&lt;li&gt;In that function its first check &lt;i&gt;navigator.geolocation&lt;/i&gt;&amp;nbsp;supported or not.&lt;/li&gt;
&lt;li&gt;It calls Inbuilt JavaScript method &lt;i&gt;getCurrentPosition &lt;/i&gt;which returns &lt;i&gt;Postion &lt;/i&gt;object&lt;/li&gt;
&lt;li&gt;This &lt;i&gt;Position &lt;/i&gt;object used by &lt;i&gt;showPostion &lt;/i&gt;to display &lt;i&gt;Latitude &lt;/i&gt;and &lt;i&gt;Logitude&lt;/i&gt;&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;
&lt;br /&gt;
Below is handleError function that used to handle any error which might occur while accessing GeoLocation of the user. 
&lt;br /&gt;
&lt;pre  class="brush: csharp"&gt;  function HandleError(error)
  {
    switch(error.code) 
    {
     case error.PERMISSION_DENIED:
      alert("User denied the request for Geolocation.");
      break;
     case error.POSITION_UNAVAILABLE:
      alert("Location information is unavailable.");
      break;
     case error.TIMEOUT:
      alert("The request to get user location timed out.");
      break;
     case error.UNKNOWN_ERROR:
      alert("An unknown error occurred.");
      break;
    }
  }
&lt;/pre&gt;
Code of the function is self-explained by the values given.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Update GeoLocation as you Move with &lt;i&gt;watchPosition&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
There is one of function which is part of Gelocation API that is very useful to get continues update of location as user moves from one place to another palce.
&lt;br /&gt;
&lt;i&gt;watchPosition&lt;/i&gt; - function that is used to achieve the above function.
&lt;br /&gt;
To see how this works actually just replace &lt;i&gt;getCurrentPosition&lt;/i&gt; function with &lt;i&gt;watchPosition&lt;/i&gt;.
&lt;br /&gt;
To stop updates from &lt;i&gt;watchPosition &lt;/i&gt;you can use&amp;nbsp;&lt;span style="background-color: white; font-family: verdana, helvetica, arial, sans-serif; font-size: 12px;"&gt;&lt;i&gt;clearWatch() &lt;/i&gt;of API.&lt;/span&gt;&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Position Object&lt;/b&gt;
&lt;br /&gt;
Both method returns Postion object as output. Following is list of property that is part of Position Object.&lt;br /&gt;
&lt;br /&gt;
&lt;table&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;coords.latitude&lt;/td&gt;&lt;td&gt;The latitude as a decimal number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;coords.longitude&lt;/td&gt;&lt;td&gt;The longitude as a decimal number&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;coords.accuracy&lt;/td&gt;&lt;td&gt;The accuracy of position&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;coords.altitude&lt;/td&gt;&lt;td&gt;The altitude in meters above the mean sea level&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;coords.altitudeAccuracy&lt;/td&gt;&lt;td&gt;The altitude accuracy of position&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;coords.heading&lt;/td&gt;&lt;td&gt;The heading as degrees clockwise from North&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;coords.speed&lt;/td&gt;&lt;td&gt;The speed in meters per second&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;&lt;td&gt;timestamp&lt;/td&gt;&lt;td&gt;The date/time of the response&lt;/td&gt; &lt;/tr&gt;
&lt;/tbody&gt;&lt;/table&gt;

&lt;b&gt;Leave comment if you have any query or if you like it.&lt;/b&gt;
&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2013/01/geolocation-api-in-html5.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-424547038401998017</guid><pubDate>Tue, 22 Jan 2013 07:51:00 +0000</pubDate><atom:updated>2013-01-23T12:57:06.407-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Index of Collection Using Linq</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
This is small post regarding How to get the index of each element in collection. There are sometime requirement to bind list of element with the dropdwon or list control with index as value and Data as Text value in this case you need to get index for each element.&lt;br /&gt;
&lt;br /&gt;
Following is piece of code that make use of Linq and get the indexes for each element in collection.

&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;

//example of getting index of List Element
List&amp;lt;string&amp;gt; ListItems = 
       new List&amp;lt;string&amp;gt; { "Test1", "Test2", "Test3", "Test4" };
var ListWithIndex= someItems.Select((item, index) =&amp;gt; new
{
      ItemName = item,
      Position = index
});

//example of getting index of Array Element
string[] ArryItem= { "Item1", "Item2", "Item3", "Item4" };
var ArraywithInex= someItems.Select((item, index) =&amp;gt; new
{
      ItemName = item,
      Position = index
});
&lt;/pre&gt;
As you see in code there is one lambda function passed in the Select function of linq, and another point to note down is each elemtn has index associated with it. So by applying function like above in linq its easy to get the index of element.   
&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2013/01/index-of-collection-using-linq.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-8832474718434073782</guid><pubDate>Fri, 04 Jan 2013 08:15:00 +0000</pubDate><atom:updated>2013-01-07T12:35:28.755-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Display and Format Negative Currency value</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
This small tip about how to show the negative currency value in your application. For Example if you have currency value like -1234 and you want to display it like -$1,234 according to you culture.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem&lt;/b&gt;&lt;br /&gt;
In C# to one of the way to format currency value easily is  use &lt;i&gt;ToString("c")&lt;/i&gt; with value will do work for you. For example  check below code
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//format -1234 as currency..
Console.WriteLine((-1234).ToString("c"));
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Output&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
This will display value in output like this &lt;i&gt;($1,234.00)&lt;/i&gt;. But the actual problem with the formatting is its not displaying - sign with currency value.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
So to come out of this You need to create a custom &lt;i&gt;NumberFormatInfo &lt;/i&gt;from your current locale. Then you can specify it's &lt;i&gt;CurrencyNegativePattern&lt;/i&gt;, for example:
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;CultureInfo currentCulture = Thread.CurrentThread.CurrentCulture;
CultureInfo newCulture = new CultureInfo(currentCulture.Name);
newCulture.NumberFormat.CurrencyNegativePattern = 1;
Thread.CurrentThread.CurrentCulture = newCulture;
Console.WriteLine((-1234).ToString("c"));
&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;&lt;i&gt;Output&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Now output of the above code is &lt;i&gt;-$1,234.00&lt;/i&gt;. That's what actually needed display negative sign for negative currency value.
&lt;br /&gt;
So in above code actual trick done by NumberFormatInfo.CurrencyNegativePattern Property, which is set to 1 which associated with pattern &lt;i&gt;&lt;b&gt;-$n&lt;/b&gt;&lt;/i&gt;. There number of different pattern supported which you can check on MSDN and assign value to property according to your need. This will not affect positive value of currency i.e. if you pas 1234 as value its dispaly as $1,234 only. And for this this example my current culture is "&lt;i&gt;en-US&lt;/i&gt;" .
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
I Hope you all like this simple and easy example of formatting negative currency. you can explore more on MSDN on reference provided at end of post.&lt;br /&gt;
&lt;b&gt;&lt;i&gt;NumberFormatInfo Class&lt;/i&gt;&lt;/b&gt; -&amp;nbsp;&lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.aspx"&gt;http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.aspx&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;NumberFormatInfo.CurrencyNegativePattern Property&lt;/i&gt;&lt;/b&gt; -&lt;a href="http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencynegativepattern.aspx"&gt; http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.currencynegativepattern.aspx&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Leave comment if you have any query or if you like it.&lt;/b&gt;&lt;/div&gt;
</description><link>http://pranayamr.blogspot.com/2013/01/display-and-format-negative-currency.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-7630040314788972090</guid><pubDate>Mon, 31 Dec 2012 10:34:00 +0000</pubDate><atom:updated>2013-01-01T13:18:52.725-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Intermediate</category><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Tuple Type in C#4.0</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;b&gt;What is Tuple type ?&lt;/b&gt;
&lt;br /&gt;
Tuple is new class type added in C#4.0. Tuple type allows to create data structure which is consist of specific type and specific number of elements. In the following post its about basic of Tuple type, how and where to use this new type in your code.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;How to create Tuple type object&lt;/b&gt;&lt;br /&gt;
Following code show how you can create and use this class type.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Console.WriteLine("How to create and use");
Tuple&amp;lt;int, string&amp;gt; tuple = new Tuple&amp;lt;int, string&amp;gt;(1, "pranay");
Console.WriteLine(tuple.Item1 + "-" + tuple.Item2);
&lt;/pre&gt;
One way to create object is just make use of constructor and create the Tuple object.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Tuple&amp;lt;int, string&amp;gt; tuple1 = Tuple.Create(2, "ab1");
Console.WriteLine(tuple1.Item1 + "-" + tuple1.Item2);
Console.WriteLine();
&lt;/pre&gt;
Second way is make use of Create Static method supported by Tuple class and create object.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Refer Element of Tuple Object&lt;/b&gt;&lt;br /&gt;
As you see in both example element of Tuple get&amp;nbsp;referred&amp;nbsp;using name Item1 and Item2, so this is predefined name for the element by .net framework only. So to&amp;nbsp;refer&amp;nbsp;element in Tuple object you need to write "Item+number_of_the_element".&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Constrain&lt;/b&gt;&lt;br /&gt;
You cannot change value of the the property of Tuple object.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;
// after creation of object this is not possible
// this gives compile time error
tuple1.Item1 = 100; 
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;C# allows to create Tuple object with the 7 different type element. 
&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Create&amp;lt;T1&amp;gt;(T1) Creates a new 1-tuple, or singleton.
Create&amp;lt;T1, T2&amp;gt;(T1, T2) Creates a new 2-tuple, or pair.
Create&amp;lt;T1, T2, T3&amp;gt;(T1, T2, T3) Creates a new 3-tuple, or triple.
Create&amp;lt;T1, T2, T3, T4&amp;gt;(T1, T2, T3, T4) Creates a new 4-tuple, or quadruple.
Create&amp;lt;T1, T2, T3, T4, T5&amp;gt;(T1, T2, T3, T4, T5) Creates a new 5-tuple, or quintuple.
Create&amp;lt;T1, T2, T3, T4, T5, T6&amp;gt;(T1, T2, T3, T4, T5, T6) Creates a new 6-tuple, or sextuple.
Create&amp;lt;T1, T2, T3, T4, T5, T6, T7&amp;gt;(T1, T2, T3, T4, T5, T6, T7) Creates a new 7-tuple, or septuple.
&lt;/pre&gt;
&lt;pre&gt;&lt;/pre&gt;
&lt;b&gt;What to do if you want to have more than 8 values ?&lt;/b&gt;&lt;br /&gt;
Last variation of Tuple creation allows to create Tuple object with more than 8 different element.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Create&amp;lt;T1, T2, T3, T4, T5, T6, T7, T8&amp;gt;(T1, T2, T3, T4, T5, T6, T7, T8) Creates a new 8-tuple, or octuple. 
&lt;/pre&gt;
in this T8 element is of type Tuple only that means if you want to create tuple more than 8 it will be like this 
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var num = new Tuple&amp;lt;int, int, int, int, int, int, int, 
                 Tuple&amp;lt;int&amp;gt;&amp;gt;(1, 2, 3, 4, 5, 6, 7, 
                 new Tuple&amp;lt;int&amp;gt;(8));
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Use Of Tuple type&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;To Pass data To methods&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Sometime we just create class or structure to just pass data to method, creation of this extra class or structure in code can be avoided by using Tuple object to pass data.&lt;br /&gt;
Following is example of this where object of Tuple used to pass int and string data. And its shows that we can also create list of Tuple object and pass to method for processing. 
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;ProcessData(new Tuple&amp;lt;int, string&amp;gt;(1, "Pranay"));

List&amp;lt;Tuple&amp;lt;int, String&amp;gt;&amp;gt; lst = new List&amp;lt;Tuple&amp;lt;int, string&amp;gt;&amp;gt;();
lst.Add(new Tuple&amp;lt;int, string&amp;gt;(1, "Pranay"));
lst.Add(Tuple.Create(2, "ab1"));
lst.Add(Tuple.Create(1, "abcdef"));
lst.Add(Tuple.Create(3, "cd2"));
ProcessListOfData(lst);&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;//Process single Tuple object
public static void ProcessData(Tuple&amp;lt;int, string&amp;gt; tup)
{
    Console.WriteLine("ProcessData");
    Console.WriteLine(tup.Item1 + "-" + tup.Item2);
    Console.WriteLine();
}
//Process list of Tuple object
public static void ProcessListOfData(List&amp;lt;Tuple&amp;lt;int, String&amp;gt;&amp;gt; lst)
{
    Console.WriteLine("ProcessListOfData");
    var data = lst.Where(x =&amp;gt; x.Item1 == 1).Select(x =&amp;gt; x);
    foreach (var tup in data)
    {
       Console.WriteLine(tup.Item1 + "-" + tup.Item2);
    }
    Console.WriteLine();
}
&lt;/pre&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;
&lt;b&gt;&lt;i&gt;To Return From the Method&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Tuple can be used to return data from method where you want to return more than one value or list of object without creating extra class or structure for carrying data.
&lt;br /&gt;
Following is example of returning data type.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var data = ReturnTupleData();
Console.WriteLine(data.Item1 + "-" + data.Item2);
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static Tuple&amp;lt;int, string&amp;gt; ReturnTupleData()
{
    return new Tuple&amp;lt;int, string&amp;gt;(1, "pranay");
}
&lt;/pre&gt;
As you can see it use Tuple object to return int and string data which is not possible with the normal method because we only have one return type.
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;/b&gt;
&lt;b&gt;&lt;i&gt;To Return Anonymous Type&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Following is example of using Tuple with linq where most of the time we return anonymous type from the method because we just have to select only require number of property from set of property object have.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;foreach (var tup in ProcessListOfDataAndReturn(lst))
{
     Console.WriteLine(tup.Item1 + "-" + tup.Item2+"-" + tup.Item3);
}
Console.WriteLine();
&lt;/pre&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static IEnumerable&amp;lt;Tuple&amp;lt;int, string, int&amp;gt;&amp;gt; ProcessListOfDataAndReturn(List&amp;lt;Tuple&amp;lt;int, String&amp;gt;&amp;gt; lst)
{
     Console.WriteLine("ProcessListOfDataAndReturn");
     var data = from tup in lst
                select new Tuple&amp;lt;int, string, int&amp;gt;
                    (
                        tup.Item1,
                        tup.Item2,
                        tup.Item2.Length
                     );
     return data.ToList();
}
&lt;/pre&gt;
You cannot return anonymous type from the method which is one of the constrain. There are other ways to return it from the method which is already discuss by me here &lt;a href="http://pranayamr.blogspot.ca/2012/10/return-anonymous-type.html"&gt;Return Anonymous type&lt;/a&gt;.&lt;br /&gt;
But with the help of Tuple we can easily return Anonymous type data which you can see in above code.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
This inbuilt Tuple class in C#4.0 can be use to avoid issue discuss above and also to simplify code at some point 
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Full Source code &lt;/b&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TupleTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("How to crate and use");
            Tuple&amp;lt;int, string&amp;gt; tuple = new Tuple&amp;lt;int, string&amp;gt;(1, "pranay");
            Tuple&amp;lt;int, string&amp;gt; tuple1 = Tuple.Create(2, "ab1");
            Console.WriteLine(tuple.Item1 + "-" + tuple.Item2);
            Console.WriteLine(tuple1.Item1 + "-" + tuple1.Item2);
            Console.WriteLine();
         
            ProcessData(new Tuple&amp;lt;int, string&amp;gt;(1, "Pranay"));

            List&amp;lt;Tuple&amp;lt;int, String&amp;gt;&amp;gt; lst = new List&amp;lt;Tuple&amp;lt;int, string&amp;gt;&amp;gt;();
            lst.Add(new Tuple&amp;lt;int, string&amp;gt;(1, "Pranay"));
            lst.Add(Tuple.Create(2, "ab1"));
            lst.Add(Tuple.Create(1, "abcdef"));
            lst.Add(Tuple.Create(3, "cd2"));
            ProcessListOfData(lst);

            Console.WriteLine("ReturnTupleData");
            var data = ReturnTupleData();
            Console.WriteLine(data.Item1 + "-" + data.Item2);
            Console.WriteLine();

            foreach (var tup in ProcessListOfDataAndReturn(lst))
            {
                Console.WriteLine(tup.Item1 + "-" + tup.Item2+"-" + tup.Item3);
            }
            Console.WriteLine();

            Console.ReadLine();
        }

        public static void ProcessData(Tuple&amp;lt;int, string&amp;gt; tup)
        {
            Console.WriteLine("ProcessData");
            Console.WriteLine(tup.Item1 + "-" + tup.Item2);
            Console.WriteLine();
        }


        public static void ProcessListOfData(List&amp;lt;Tuple&amp;lt;int, String&amp;gt;&amp;gt; lst)
        {
            Console.WriteLine("ProcessListOfData");
            var data = lst.Where(x =&amp;gt; x.Item1 == 1).Select(x =&amp;gt; x);
            foreach (var tup in data)
            {
                Console.WriteLine(tup.Item1 + "-" + tup.Item2);
            }
            Console.WriteLine();
        }

        public static Tuple&amp;lt;int, string&amp;gt; ReturnTupleData()
        {
            return new Tuple&amp;lt;int, string&amp;gt;(1, "pranay");
        }

        public static IEnumerable&amp;lt;Tuple&amp;lt;int, string, int&amp;gt;&amp;gt; ProcessListOfDataAndReturn(List&amp;lt;Tuple&amp;lt;int, String&amp;gt;&amp;gt; lst)
        {
            Console.WriteLine("ProcessListOfDataAndReturn");
            var data = from tup in lst
                       select new Tuple&amp;lt;int, string, int&amp;gt;
                       (
                           tup.Item1,
                           tup.Item2,
                           tup.Item2.Length
                       );
            return data.ToList();
        }
    }
}&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Leave comment if you have any query or if you like it.&lt;/b&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/12/tuple-type-in-c40.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-2927884130200882647</guid><pubDate>Fri, 21 Dec 2012 10:30:00 +0000</pubDate><atom:updated>2013-01-23T13:01:26.388-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SilverLight</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">WCF</category><title>Dispatcher in Silverlight</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div&gt;
&lt;a href="http://www.codeproject.com/Articles/477525/Silverlight-Application-with-Dispatcher" target="_blank"&gt;Download Code&lt;/a&gt;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this I am going to discuss about Dispatcher that makes Silverlight application responsive. I am going to show how Dispatcher allows to update UI of the application on the response from WCF service which is called anonymously and while continue to execute the other task.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Read More :&lt;/b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/system.windows.dependencyobject.dispatcher%28v=vs.95%29.aspx"&gt; DependencyObject.Dispatcher Property&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;What is the Example Application about ?&lt;/b&gt;&lt;br /&gt;
This is application which is fill up the Listbox on UI with the help of Dispather and WCF service which get called Asychronously so the actually thread do the task and doesnt get block.&lt;br /&gt;
Secondly On button click on UI its select the product in list which is get fetch using Dispatcher and WCF service.&lt;br /&gt;
So application is&amp;nbsp;demonstration&amp;nbsp;of how to use Dispatcher in Silverlight application which make use application more responsive and update UI without blocking other thread.&lt;br /&gt;
&lt;br /&gt;
UI of the silverlight page&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://1.bp.blogspot.com/-QNWhyKg4m5I/UIpq2-tE86I/AAAAAAAADTw/jBg341L9OLE/s1600/s+creen1.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="166" src="http://1.bp.blogspot.com/-QNWhyKg4m5I/UIpq2-tE86I/AAAAAAAADTw/jBg341L9OLE/s320/s+creen1.JPG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
in the page "List of Item" item page Listbox get filled with the help of Dispatcher and by calling WCF service&amp;nbsp;asynchronous.&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-jM3yjJSdwjs/UIpq7OmVo7I/AAAAAAAADT4/9zlDxpc6_x8/s1600/s+creen2.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="176" src="http://3.bp.blogspot.com/-jM3yjJSdwjs/UIpq7OmVo7I/AAAAAAAADT4/9zlDxpc6_x8/s320/s+creen2.JPG" width="320" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
Secondly on Button click&amp;nbsp; items get selected in listbox which are get fetched by making&amp;nbsp;asynchronous WCF&amp;nbsp;service call and UI get updated by Dispatcher. &lt;br /&gt;
&lt;br /&gt;
Now in following article going to show detail execution of the code behind this Silverlight page and how the Dispatcher&amp;nbsp; and&amp;nbsp;asynchronous&amp;nbsp;WCF service combination works&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Structure of the application&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://2.bp.blogspot.com/-CWeb8SpH6wc/UJJ51zfT-TI/AAAAAAAADUU/Fs5B-q5yFbc/s1600/silveright+structure.bmp" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="320" src="http://2.bp.blogspot.com/-CWeb8SpH6wc/UJJ51zfT-TI/AAAAAAAADUU/Fs5B-q5yFbc/s320/silveright+structure.bmp" width="230" /&gt;&lt;/a&gt;&lt;/div&gt;
Above is structure of the application its&amp;nbsp;consist&amp;nbsp;of three project&lt;br /&gt;
1) DataService - project contains WCF service(s).&lt;br /&gt;
2) BusinessApplication1 - Silverlight application i.e. application pages developed using Silverlight.&lt;br /&gt;
3)&amp;nbsp;BusinessApplication1.Web - It host Silverlight application.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;DataService Project&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;WCF service &lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
WCF file is part of "DataServicwe" project in application structure. Service file of this application contains following two methods&lt;br /&gt;
&lt;i&gt;GetList &lt;/i&gt;- &amp;nbsp;this method get called to return the list of all product , once call is done on UI you can see the list of product get populated.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public List&amp;lt;string&amp;gt; GetList()
{
    List&amp;lt;string&amp;gt; lst = new List&amp;lt;string&amp;gt;
                {"Product1","Product2","Product3","Product4","Product5"};
    return lst;
}
&lt;/pre&gt;
&lt;/div&gt;
&lt;i&gt;GetSelectedList &lt;/i&gt;- this method get list of selected products, which is get&amp;nbsp;highlighted&amp;nbsp;once use press button on UI.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public List&lt;string&gt; GetSelectedList()
{
    List&amp;lt;string&amp;gt; lst = new List&amp;lt;string&amp;gt;
                          {"Product1","Product3","Product5"};
    return lst;
}
&lt;/string&gt;&lt;/pre&gt;
&lt;b&gt;Note &lt;/b&gt;: Right now for the demo this methods directly return list of string which is hard-coded but in actual scenario this get replace by database call i.e. call to database to get the list of product and call to database to get list of product belonging to user.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;BusinessApplication1 (Silverlight Application)&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;WCF proxy&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
Proxy is class file which calls WCF service and return response to UI i.e. its bridge between Silvelright UI and WCF service.&lt;br /&gt;
Following variable is object of WCF client service class which is generated by visual studio from WCF service which is used in Silvelright application.&lt;br /&gt;
&lt;pre&gt;Service1Client svr;
&lt;/pre&gt;
&lt;i&gt;GetData&lt;/i&gt; Method is called from the xaml.cs page to fill the&amp;nbsp;available&amp;nbsp;product list which is on UI of application.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public void GetData(Action&amp;lt;ObservableCollection&amp;lt;string&amp;gt;,Exception&amp;gt; ac)
{
    svr = new Service1Client();
    svr.GetListAsync(ac);
    svr.GetListCompleted += 
       new EventHandler&amp;lt;GetListCompletedEventArgs&amp;gt;(svr_GetListCompleted);
}
&lt;/pre&gt;
in above method first line of method create instace of WCF client class.&lt;br /&gt;
Second line of code call to "GetListAsync" method which is generated by Visual studio and part of WCF Client class , this method is generated from "GetList" of WCF service which we discussed earlier. "ac" is passed as argument to which is method that is used for callback i.e. its XAML.CS method which do the changes in UI.&lt;br /&gt;
Third line of code set the event handler which is&amp;nbsp;handle&amp;nbsp;the event of completion of execution on WCF service.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;svr_GetListCompleted&lt;/i&gt;&amp;nbsp;Following method get called when WCF service&amp;nbsp;complete&amp;nbsp;execution and return response of async call made to service.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;void svr_GetListCompleted(object sender, GetListCompletedEventArgs e)
{
    try
    {
     ObservableCollection&amp;lt;string&amp;gt; str = e.Result as ObservableCollection&amp;lt;string&amp;gt;;

     Deployment.Current.Dispatcher.BeginInvoke(
          (Action)(() =&amp;gt;
          {
            (e.UserState as Action&amp;lt;ObservableCollection&amp;lt;string&amp;gt;, Exception&amp;gt;)(str, null);
          }));


    }
    catch (Exception ex)
    {
        Deployment.Current.Dispatcher.BeginInvoke(
           (Action)(() =&amp;gt;
           {
             (e.UserState as Action&amp;lt;ObservableCollection&amp;lt;string&amp;gt;, Exception&amp;gt;)(null, ex);
           }));
    }
    finally
    {
       svr.GetListCompleted -= svr_GetListCompleted;
       svr.CloseAsync();
       svr = null;

     }
}
&lt;/pre&gt;
in the above method , In try block first line get the result of execution i.e. list of product which is return from WCF service.&lt;br /&gt;
Now in second line of code in try block Dispatcher calls method of UI whose reference is passed as object by "GetListAsync".&lt;br /&gt;
In Catch block if there is any&amp;nbsp;exception&amp;nbsp;occurs during execution than it get sent to UI method to display user.&lt;br /&gt;
In Finally block it remove&amp;nbsp;complete&amp;nbsp;handler and closeAsync call and set WCF client class object to null.&lt;br /&gt;
&lt;b&gt;Note : &lt;/b&gt;You find similar method for button click and select product in product list.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Page CS file&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;      public MainPage()
        {
            InitializeComponent();
            LoadList();
        }
&lt;/pre&gt;
&amp;nbsp;first line in the method&amp;nbsp;Initialize&amp;nbsp;the page component and second line of code make call to fill the product list.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;        private void LoadList()
        {
            WCFProxy proxy = new WCFProxy();
            proxy.GetData(new Action&amp;lt;ObservableCollection&amp;lt;string&amp;gt;, Exception&amp;gt;(DispalyList));

        }
&lt;/pre&gt;
This method creates the object of Proxy class which is discuss earlier and call the "GetData" method of it, as pass the&amp;nbsp;reference&amp;nbsp;of function called "DisplayList".&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public void DispalyList(ObservableCollection&amp;lt;string&amp;gt; data, Exception ex)
        {
            if (ex == null)
                listBox1.ItemsSource = data;
        }
&lt;/pre&gt;
code in this method fill the Listbox with the items once call to WCF service completed.&lt;br /&gt;
&lt;br /&gt;
Below code works same as filling product list code, But this code actually select items in productlist which actually fetch by calling WCF service. This get called on button click of Button of UI.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;private void button1_Click(object sender, RoutedEventArgs e)
        {
            WCFProxy proxy = new WCFProxy();
            proxy.GetDataSelected(new Action&amp;lt;ObservableCollection&amp;lt;string&amp;gt;, Exception&amp;gt;(SelecteItems));
        }
public void SelecteItems(ObservableCollection&amp;lt;string&amp;gt; data, Exception ex)
        {
            if (ex == null)
            {
                foreach (string s in data)
                    listBox1.SelectedItems.Add(s);
            }
        } 
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Main xaml &lt;/i&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
Following is XAML code that is for the UI of application&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;UserControl 
&amp;nbsp; x:Class="BusinessApplication1.MainPage"
&amp;nbsp; xmlns="&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;
    http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/a&gt;" 
&amp;nbsp; xmlns:x="&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;
 http://schemas.microsoft.com/winfx/2006/xaml&lt;/a&gt;"
&amp;nbsp; xmlns:navigation="clr-namespace:System.Windows.Controls;assembly
=System.Windows.Controls.Navigation" 
&amp;nbsp;
 xmlns:uriMapper="clr-namespace:System.Windows.Navigation;assembly
=System.Windows.Controls.Navigation"
&amp;nbsp;
 xmlns:dataControls="clr-namespace:System.Windows.Controls;assembly=
System.Windows.Controls.Data.DataForm.Toolkit" 
&amp;nbsp; 
&amp;nbsp; xmlns:d="&lt;a href="http://schemas.microsoft.com/expression/blend/2008"&gt;
  http://schemas.microsoft.com/expression/blend/2008&lt;/a&gt;" 
  xmlns:mc="&lt;a href="http://schemas.openxmlformats.org/markup-compatibility/2006"&gt;
  http://schemas.openxmlformats.org/markup-compatibility/2006&lt;/a&gt;" 
&amp;nbsp; mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"&amp;gt;

&amp;nbsp; &amp;lt;Grid x:Name="LayoutRoot" &amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ListBox Height="149" HorizontalAlignment="Left" Margin="152,12,0,0" Name="listBox1"
 VerticalAlignment="Top" Width="182" /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;TextBlock Height="23" 
HorizontalAlignment="Left" Margin="39,30,0,0" 
Name="textBlock1" Text="List of Item" VerticalAlignment="Top" /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;lt;Button Content="Select Item beloging to user" Height="23" 
HorizontalAlignment="Left" Margin="152,186,0,0" Name="button1"
 VerticalAlignment="Top" Width="182" Click="button1_Click" /&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Grid&amp;gt;
&amp;lt;/UserControl&amp;gt;&amp;nbsp;&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
So this helps to build more responsive Silverlight application using Dispatcher.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Leave comment if you have any query or if you like it.&lt;/b&gt;&lt;br /&gt;
&amp;nbsp; &lt;/div&gt;
</description><link>http://pranayamr.blogspot.com/2012/12/dispatcher-in-silverlight.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-QNWhyKg4m5I/UIpq2-tE86I/AAAAAAAADTw/jBg341L9OLE/s72-c/s+creen1.JPG" height="72" width="72" /><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-9045637956438530654</guid><pubDate>Tue, 11 Dec 2012 08:00:00 +0000</pubDate><atom:updated>2012-12-11T13:13:26.310-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Intermediate</category><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Convert DateTime string to DateTime variable</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post I am going to discuss about Conversion of String data in to DateTime.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Problem&lt;/b&gt;&lt;br /&gt;
For most of the beginner developer they face the problem when "Inserting or Updating" DateTime value in "Database" which is having different presentation of DateTime value than DateTime string entered in UI of Application. For Example DatTime input accept date in format "DD/MM/YYYY" i.e "26/06/2013" so when try to insert this type of DateTime data in DateTime column in database it cause problem and not allow to insert data in Database. 
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
So to Avoid problem related to during database operation its better to convert DateTime string in DateTime variable i.e. convert entered datetime string value in datetime value. So to do it two thing require to do &lt;br /&gt;
1. its better to check in code that string is proper i.e. string is valid Datetime string or not.&lt;br /&gt;
2. And convert string of datetime in Database acceptable format to avoid error. 
&lt;br /&gt;
To achieve this in .net provide function called TryParseExact which allows to check the datetime string is valid or not and convertable to DateTime variable.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Example: 
&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;string dateTimeString = "28/08/2012";
var date=DateTime.ParseExact(dateTimeString, "dd/MM/yyyy", null).ToString("MM/dd/yyyy");
&lt;/pre&gt;
In above example is conversion take place from "dd/MM/yyyy" to "MM/dd/yyyy".
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Note :&lt;/b&gt; &lt;br /&gt;
Just confirm that the format of the string representation must match the specified format exactly.
&lt;br /&gt;
&lt;br /&gt;
Following is code taken from MSDN which shows how this function works for different format. 
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;    string[] dates =
    {
      "31/12/2010",
      "12/31/2010",
      "1/1/2011",
      "1/12/2011",
      "12-12-2010",
      "12-Dec-10",
      "12-December-2010"
    };
    string[] formattedDates = new string[dates.Length];

    string[] formats = { "M/d/yyyy", "d/M/yyyy", "M-d-yyyy",
                        "d-M-yyyy", "d-MMM-yy", "d-MMMM-yyyy", };
    for (int i = 0; i &amp;lt; dates.Length; i++)
    {
      DateTime date;
      if (DateTime.TryParseExact(dates[i], formats,
                                CultureInfo.InvariantCulture,
                                 DateTimeStyles.None, out date))
        formattedDates[i] = date.ToString("dd/MM/yyyy");
    }
&lt;/pre&gt;
&lt;br /&gt;
You take reference of MSDN for creating custom format string. -&lt;a href="http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx"&gt; Custom Date and Time Format Strings&lt;/a&gt;
&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
So by using this function you avoid error of conversion of DateTime string at&amp;nbsp;run-time&amp;nbsp;easily.&lt;br /&gt;
Reference : &lt;a href="http://msdn.microsoft.com/en-us/library/system.datetime.tryparseexact.aspx"&gt;DateTime.TryParseExact&lt;/a&gt; 
&lt;br /&gt;
&lt;br /&gt;
Leave your comments if you like it.&lt;/div&gt;
</description><link>http://pranayamr.blogspot.com/2012/12/convert-date-to-your-formate.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-9006018833396157589</guid><pubDate>Mon, 26 Nov 2012 11:16:00 +0000</pubDate><atom:updated>2012-11-26T08:41:53.699-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Intermediate</category><category domain="http://www.blogger.com/atom/ns#">Sql Server</category><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Entity Framework</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Linq Query to compare only Date part of DateTime</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post I am going to discuss about comparing the date part of the datetime in linq query. In linq query its easy to perform datetime comparison how to compare only date not time part of datetime filed of your entity. &lt;br /&gt;
&lt;br /&gt;
Let have coloseure look, In Sql Server one can do something like as below to just compare date part of the field.
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;SELECT * FROM dbo.tbl_MyTable
WHERE 
CAST(CONVERT(CHAR(10), DateTimeValueColumn, 102) AS DATE) = 
            CAST(CONVERT(CHAR(10),GETDATE(),102) AS DATE)
&lt;/pre&gt;
So in above query convert function did task of removing time part and only date part comparison happens.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Linq Queires&lt;/b&gt;&lt;br /&gt;
Following discussion about doing same task using linq queries. 
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Solution 1:&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
First way to achieve same thing (i.e. comparing date part) of entity or object is following 
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var data = context.t_quoted_value.Where(x =&amp;gt; x.region_name == "Hong Kong"&amp;nbsp;
                  &amp;amp;&amp;amp; DateTime.Compare(x.price_date.Value.Date, dt.Date) == 0)
                  .ToList();
&lt;/pre&gt;
&lt;br /&gt;
Here Date property of DatTime used to get only date part of datetime property and made use of DateTime.Compare function to get matching object.
&lt;br /&gt;
&lt;br /&gt;
But the problem with this approach when make use of EnityFramework i.e. Linq To Entity , its gives following error at runtime &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The specified type member 'Date' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
so to avoid above error in Linq to Entity&amp;nbsp;query is modified to following&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var data = context.t_quoted_value.Where(x =&amp;gt; x.region_name == "Hong Kong")
                            .ToList()
                            .Where (x=&amp;gt; DateTime.Compare(x.price_date.Value.Date, dt.Date) == 0)
                            .ToList(); 
&lt;/pre&gt;
&lt;br /&gt;
So in above query first data is get fetched from the database and than on list date comparison get applied. But the problem with this approach is need to load all data first than the date comparison get applied because entityframework doesn't support direct query.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Solution 2:&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
One more easy and simple solution to just compare datet part of datetime object is as following
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;            
var data1 = context.t_quoted_value.Where(x =&amp;gt; x.region_name == "Hong Kong" 
                            &amp;amp;&amp;amp; x.price_date.Value.Year == dt.Year
                            &amp;amp;&amp;amp; x.price_date.Value.Month == dt.Month
                            &amp;amp;&amp;amp; x.price_date.Value.Day == dt.Day).ToList();
&lt;/pre&gt;
its query use the year,month and day property of datetime object to compare date. Advantage of this solution is this is compatible with all flavor of Linq i.e. it works in linq to sql, linq to object and also in linq to enitity.
&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
So the post is useful when you need to compare only date part of datetime property in Linq queries.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Leave your comments if you like it.&lt;/b&gt;
&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;
&lt;/div&gt;
</description><link>http://pranayamr.blogspot.com/2012/11/linq-query-to-compare-only-date-part-of.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-1407032725377994751</guid><pubDate>Wed, 07 Nov 2012 08:04:00 +0000</pubDate><atom:updated>2012-11-15T07:19:06.931-05:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Linq to XML</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Read Xml with Descendants Method (XName) </title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
This post is about understanding &lt;i&gt;Descendants &lt;/i&gt; and avoid misconception with this method.
&lt;br /&gt;
Recently I read one question on StackOverFlow &amp;nbsp;about reading xml using Linq To Xml to get node values. In that developer made use of Descendants&amp;nbsp;Method to get the child node values.&lt;br /&gt;
&lt;br /&gt;
Let see the actual problem here following is XML to read. And developer wrote code to read out value of orderid node.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;ordersreport date="2012-08-01"&amp;gt;
&amp;lt;returns&amp;gt;
      &amp;lt;amount&amp;gt;
        &amp;lt;orderid&amp;gt;2&amp;lt;/orderid&amp;gt;
        &amp;lt;orderid&amp;gt;3&amp;lt;/orderid&amp;gt;
        &amp;lt;orderid&amp;gt;21&amp;lt;/orderid&amp;gt;
        &amp;lt;orderid&amp;gt;23&amp;lt;/orderid&amp;gt;
      &amp;lt;/amount&amp;gt;
    &amp;lt;/returns&amp;gt;
&amp;lt;/ordersreport&amp;gt;
&lt;/pre&gt;
So code written like this
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;    var amount = documentRoot.Descendants("Amount")
               .Select(y =&amp;gt; new
               {
                  OrderId = (int)y.Element("OrderId")
               });
               foreach (var r in amount)
               {
                  Console.WriteLine(r.OrderId);
               }
&lt;/pre&gt;
Ouput of above code is&lt;br /&gt;
&amp;nbsp;2&lt;br /&gt;
that is only first orderid element value which is child of Amount , So misconception here by developer of the code is &lt;i&gt;Descendants("Amount")&lt;/i&gt; returns child element of the Amount tag i.e. all orderId element.

&lt;br /&gt;
&lt;br /&gt;
Now to &lt;b&gt;Understand &lt;i&gt;Descendants&lt;/i&gt;&lt;/b&gt; function in better way I visited to MSDN link which says something like this
&lt;br /&gt;
&lt;b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/bb353813.aspx"&gt;XContainer.Descendants Method (XName)&lt;/a&gt; &lt;/b&gt;- Returns a filtered collection of the descendant elements for this document or element, in document order. Only elements that have a matching XName are included in the collection. 

So as per the defincation on MSDN problem with code 
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;    var amount = doc.Descendants("Amount")                         
      .Select(y =&amp;gt; new
      {
       OrderId = (int)y.Element("OrderId")
       });
&lt;/pre&gt;
will give you Element &lt;i&gt;Amount&lt;/i&gt; and when you write &lt;i&gt;y.Element("OrderId")&lt;/i&gt; will return you fist element of its child.
 
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Descendants &lt;/b&gt;&lt;/i&gt;- doesn't mean than its return the child element of element name&amp;nbsp;rather&amp;nbsp;than method look for descendants of element or if name of elemnt specified as parameter than matching&amp;nbsp;descendants. 
&lt;br /&gt;
Finally I got following solution to get it properly work 
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;XElement documentRoot  = 
     XElement.Parse (@"&amp;lt;ordersreport date="2012-08-01"&amp;gt;
                             &amp;lt;returns&amp;gt;
                              &amp;lt;amount&amp;gt;
                                  &amp;lt;orderid&amp;gt;2&amp;lt;/orderid&amp;gt;                                                    
                                  &amp;lt;orderid&amp;gt;3&amp;lt;/orderid&amp;gt;
                                  &amp;lt;orderid&amp;gt;21&amp;lt;/orderid&amp;gt;
                                  &amp;lt;orderid&amp;gt;23&amp;lt;/orderid&amp;gt;
                               &amp;lt;/amount&amp;gt;
                             &amp;lt;/returns&amp;gt;
                        &amp;lt;/ordersreport&amp;gt;");
&lt;/pre&gt;
&lt;b&gt;Solution 1&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var orderids = from order in
                  documentRoot.Descendants("Amount").Descendants()
                  select new
                  {
                     OrderId = order.Value
                  };
&lt;/pre&gt;
As per the information on MSDN &lt;i&gt;documentRoot.Descendants("Amount").Descendants()&lt;/i&gt; give list of &lt;i&gt;orderId &lt;/i&gt;elements.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution 2&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var orderids = from order in
                    documentRoot.Descendants("OrderId")
                    select new
                    {
                       OrderId = order.Value
                    };
&lt;/pre&gt;
or the second solution is just bit easy than this just make use of &lt;i&gt;documentRoot.Descendants("OrderId")&lt;/i&gt; that will give all &lt;i&gt;orderid&lt;/i&gt;element.&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;
&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
This post is just for avoiding misconception related to &lt;i&gt;Descendants&lt;/i&gt; and understand it properly.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Leave your comments if you like it.&lt;/b&gt;&lt;/div&gt;

&lt;a href="http://www.blogger.com/" rel="tag" style="display: none;"&gt;CodeProject&lt;/a&gt;</description><link>http://pranayamr.blogspot.com/2012/11/read-xml-with-descendants-method-xname.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-3812743389380647660</guid><pubDate>Tue, 09 Oct 2012 19:02:00 +0000</pubDate><atom:updated>2012-10-16T02:10:28.379-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Return Anonymous type </title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;
In this post I am going to discuss about returning the anonymous type and how to handle in code. Following is list of fact about anonymous type.

&lt;b&gt;&amp;nbsp;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Quick facts about Anonymous type&lt;/b&gt;&lt;br /&gt;
&lt;ul&gt;
&lt;li&gt;Anonymous types are&amp;nbsp;reference&amp;nbsp;type derived form &lt;i&gt;system.objects&lt;/i&gt;.&lt;/li&gt;
&lt;li&gt;Properties of the Anonymous type is read only.&lt;/li&gt;
&lt;li&gt;If two Anonymous type has same properties and same order than compiler treats its as same type. But if both are in one assembly.&lt;/li&gt;
&lt;li&gt;Anonymous type has method scope. If you want to return Anonymous type form the method than you have to convert it in object type. But is not good practice.&lt;/li&gt;
&lt;/ul&gt;
You can read more on blog about this: &lt;a href="http://pranayamr.blogspot.in/2010/12/anonymous-types.html"&gt;Anonymous types &lt;/a&gt;
&lt;br /&gt;
As in about facts you cannot return anonymous type from the method , if you want to return you need to cast it in object. 
&lt;br /&gt;
Now in following post I am going to do same return the anonymous type as object and going to show three different way to handle it.
&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;
&lt;li&gt;Way 1: Handle using Dynamic type&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Way 2: Handle by creating same anonymous type&amp;nbsp;&lt;/li&gt;
&lt;li&gt;Way 3: Handle using Reflection
&lt;/li&gt;
&lt;/ul&gt;
To Understand each way I created following method which returns anonymous type
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;object AnonymousReturn()
{
     return new { Name = "Pranay", EmailID = "pranayamr@gmail.com" }; 
}
&lt;/pre&gt;
&lt;b&gt;Way 1: Handle using Dynamic type&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;dynamic newtype= AnonymousReturn();
Console.WriteLine(newtype.Name + "  " + newtype.EmailID);
&lt;/pre&gt;
As you see in above example first line of code calling method which is returning anonymous type as object and assign the return value to dynamic type. Second line of code just printing the property value of anonymous type.&lt;br /&gt;
Note : No intelligence support as we are using dynamic type. And need to remember the property name and type also.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Way 2: Handle by creating same anonymous type&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;object o = AnonymousReturn();
var obj = Cast(o, new { Name = "", EmailID = "" });
Console.WriteLine(obj.Name + "  " + obj.EmailID);
&lt;/pre&gt;
In this way return value of the anonymous type is get assigned to object. Next line of the code cast object to the same anonymous type. To accomplish this task following method does casting of object.  
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;T Cast&amp;lt;T&amp;gt;(object obj, T type) { return (T)obj; }
&lt;/pre&gt;
This done song type conversation and provide intelligence support.
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Way 3: Handle using Reflection&lt;/b&gt;
&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;object refobj = AnonymousReturn();
Type type = refobj.GetType(); 
PropertyInfo[] fields = type.GetProperties(); 
foreach (var field in fields) 
{
   string name = field.Name; 
   var temp = field.GetValue(obj, null);
   Console.WriteLine(name + "  " + temp);
}
&lt;/pre&gt;
This way making use of reflection feature of .net. First line of code call the method and assign return value to refobj. Second line of code get the Type of the object and than following line of code get the property of anonymous type and print value of it.&lt;br /&gt;
&lt;b&gt;Check out full Source code of to test all technique we discuss&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;using System;p
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            Program p = new Program();
            dynamic newtype= p.AnonymousReturn();
            Console.WriteLine("With Dynamic Type");
            Console.WriteLine(newtype.Name + "  " + newtype.EmailID);
            Console.WriteLine();
            Console.WriteLine("With Creation of same anonymous type");
            object o = p.AnonymousReturn();
            var obj = p.Cast(o, new { Name = "", EmailID = "" });
            Console.WriteLine(obj.Name + "  " + obj.EmailID);
            Console.WriteLine();
            Console.WriteLine("With Reflection");
            object refobj = p.AnonymousReturn();
            Type type = refobj.GetType(); 
            PropertyInfo[] fields = type.GetProperties(); 
            foreach (var field in fields) 
            {
                string name = field.Name; 
                var temp = field.GetValue(obj, null);
                Console.WriteLine(name + "  " + temp);
            }

            Console.ReadLine();
        }

         object AnonymousReturn()
        {
            return new { Name = "Pranay", EmailID = "pranayamr@gmail.com" }; 
        }

        T Cast&amp;lt;T&amp;gt;(object obj, T type) { return (T)obj; }

        public static void Write()
        {
            Program p = new Program();
            object obj = p.AnonymousReturn();
            
        }
    }
}
&lt;/pre&gt;
&lt;b&gt;Output&lt;/b&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/-P89XOY-3Q6g/UHz42Ff3VJI/AAAAAAAADTU/m1bH1k1HniA/s1600/output.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="162" src="http://3.bp.blogspot.com/-P89XOY-3Q6g/UHz42Ff3VJI/AAAAAAAADTU/m1bH1k1HniA/s640/output.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
</description><link>http://pranayamr.blogspot.com/2012/10/return-anonymous-type.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-P89XOY-3Q6g/UHz42Ff3VJI/AAAAAAAADTU/m1bH1k1HniA/s72-c/output.JPG" height="72" width="72" /><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-2351107276433117982</guid><pubDate>Tue, 04 Sep 2012 06:06:00 +0000</pubDate><atom:updated>2012-09-04T02:06:56.183-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SilverLight</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Assign ToolTip to dynamically created colum of silverlight Gridview and How to create style for element runtime</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I am going to discuss about displaying tooptip for autogenerated columns of toolkit silverlight and telerik silverlight gridcongtrol. Also goint to discuss about how to create style dynamically for the silverlight control. &lt;br /&gt;
&lt;br /&gt;
How to create style in codebehind i.e. runtime for control To define the style sheet for any silverlight control on runtime there you need to do following things &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;1.&lt;/strong&gt; Create Style object with the type of control &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var style = new Style(typeof(controlType)); 
&lt;/pre&gt;Control type can be Grid, GridviewCell, Textblock etc. i.e any valid silverlight control. &lt;br /&gt;
&lt;strong&gt;2.&lt;/strong&gt; Add Setter to Created Style Object &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;style.Setters.Add(new Setter(StylePropertyName, Value));
&lt;/pre&gt;You need to pass property name and value now after this, below discussion you will find example for the same &lt;br /&gt;
&lt;strong&gt;3.&lt;/strong&gt; Attach Created Style to the control type object&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;controlboject.stylefor = style; 
&lt;/pre&gt;Now following describe how to user the dynamic style and display tooltip for header of autogenerated columns of gridview.&lt;br /&gt;
&lt;br /&gt;
To apply the style at runtime to autogetnerated column I made use of AutoGenerated Event of the grid in both of the below example.&lt;br /&gt;
&lt;strong&gt;Telerik &lt;/strong&gt;&lt;br /&gt;
Code for displaying tootip for Telerik grid&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;private void EditableGV_AutoGeneratingColumn
       (object sender, GridViewAutoGeneratingColumnEventArgs e)
{
   GridViewDataColumn column = e.Column as GridViewDataColumn;

   //for tooltip dispaly
   var style = new Style(typeof(GridViewHeaderCell));
   style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, 
                                                column.UniqueName));
   column.HeaderCellStyle = style; 
}
&lt;/pre&gt;As you see in above code Style is get created for the Headercell of grid view. ToolTip property style is added by using setting as we discuss above. Lastly assigned created style to headercell style.&lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Silverlight gridview &lt;/strong&gt;&lt;br /&gt;
Same as Telerik gird,in tool grid I made use of Autogenerated column&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;private void dataGrid1_AutoGeneratingColumn
            (object sender, DataGridAutoGeneratingColumnEventArgs e)
{
  DataGridBoundColumn column = e.Column as DataGridBoundColumn;
  var style = new Style(typeof(DataGridColumnHeader));
  style.Setters.Add(new Setter(ToolTipService.ToolTipProperty, 
                                                column.Header));
  column.HeaderStyle = style; 
}
&lt;/pre&gt;Just few code difference , here style is created for headercell only but the name of the class is diffrerent, which you can notice easily by comparing both code.&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/08/assign-tooltip-to-dynamically-created.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-2728908702894454749</guid><pubDate>Sat, 18 Aug 2012 15:53:00 +0000</pubDate><atom:updated>2012-09-04T02:04:05.363-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Delegate and Action and Func and lamda </title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;This post is about the new delegate types included in .net framework which are Action and Function. How to use this type and what is difference between this two type. Also to resolve confusion between Action, Function, Delegate and Lamda. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Action&lt;/b&gt;- This type Points to the function which return void i.e Encapsulate method which is returning void. Action is of Delegate type so its similar to delegate which is pointing to method void. Action is type which make code simple and hide the implementation of delegate.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Syntax of Action Type or Function&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&gt;public delegate void Action()
&lt;/pre&gt;other variation check on msdn : &lt;a href="http://msdn.microsoft.com/en-us/library/018hxwa8.aspx"&gt;Action&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Example of Action &lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public class ActionDemo
{
     public void ActFunction(int a)
     {
     }
     public void ActFunction1()
     {
     }

     static void Main()
     {
        ActionDemo ad = new ActionDemo();
            

        Action act1 = new Action(ad.ActFunction1);
        act1();     
        Action&amp;gt;int&amp;lt; act = new Action&amp;gt;int&amp;lt;(ad.ActFunction);
        act();
     }
}
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Func&lt;/b&gt; -This type to point the function which has return value.i.e Encapsulate method which is returning value. Func is of Delegate type so its similar to delegate which is pointing to method which returns value. Func is type which make code simple and hide the implementation of delegat which points to method which return value.&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Syntax of Func&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&gt;public delegate TResult Func&amp;gt;in T, out TResult&amp;lt;(T arg)
&lt;/pre&gt;other variation check on MSDN&amp;nbsp; : &lt;a href="http://www.blogger.com/goog_1896305836"&gt;Func&lt;/a&gt;&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/bb549151.aspx"&gt;&lt;br /&gt;
&lt;/a&gt; &lt;i&gt;&lt;b&gt;Example of Func&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public class FuncDemo
{
     public int FuncCall(int a)
     {
            return 0;
     }
     public int FuncCall1()
     {
            return 0;
     }

     static void Main()
     {
        FuncDemo fd = new FuncDemo();

        Func&amp;gt;int&amp;lt; func = new Func&amp;gt;int&amp;lt;(fd.FuncCall);
        func();
        Func&amp;gt;int,int&amp;lt; func1 = new Func&amp;gt;int,int&amp;lt;(fd.FuncCall);
        func1(2);
     }
}
&lt;/pre&gt;&lt;b&gt;Func Vs Action&lt;/b&gt;&lt;br /&gt;
Both are Delegate type. Difference between &lt;i&gt;Func&lt;/i&gt; and &lt;i&gt;Action&lt;/i&gt; is - &lt;i&gt;Func&lt;/i&gt; can point to the function which must have return value, &lt;i&gt;Action&lt;/i&gt; can point to the function which must have return type void.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Delegate vs Func , Action&lt;/b&gt;&lt;br /&gt;
&amp;nbsp;- Both Action and Function are of Delegate type, so both of this type can able to perform same function which can be perform by Delegate. &lt;br /&gt;
&amp;nbsp;- Delegate Can point to function which return value and not return value. &lt;br /&gt;
Read more about Deletegate : &lt;a href="http://msdn.microsoft.com/en-us/library/ms173171%28v=vs.80%29.aspx"&gt;Delegate&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Confusion between Lamda and Delegate, Action, Func&lt;/b&gt;&lt;br /&gt;
Lamda - Replacement of anonymous function i.e allows to create anonymous function that can contain expressions and statements, and can be used to create delegates or expression tree types. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;Action&amp;gt;string&amp;lt; act2 = n =&amp;gt; { string s = n + " " + "World"; Console.WriteLine(s); };
act2("abc");

Func&amp;gt;string, string&amp;lt; fun = (n1) =&amp;gt; { return n1; };
fun("pranay");

del myDelegate = x =&amp;gt; x * x;
    int j = myDelegate(5); 
&lt;/pre&gt;&lt;b&gt;Conclusion&lt;/b&gt;&lt;br /&gt;
So by this post you can able to figure out the difference between the types of C#. &lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/08/delegate-and-action-and-func-and-lamda.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6461064323028048411</guid><pubDate>Sat, 11 Aug 2012 20:08:00 +0000</pubDate><atom:updated>2012-08-11T16:31:43.323-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Sql Server</category><category domain="http://www.blogger.com/atom/ns#">Linq to SQL</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">Entity Framework</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Call Sql Server inbuilt functions using Linq</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;The post is about the the new class introduce in .net framwork for support of built in SQL-Server function. The &lt;i&gt;SqlFunctions&lt;/i&gt; class allows to call SQL-Server function from linq queries while using EntityFramwork.&lt;br /&gt;
&lt;br /&gt;
Following describes how it works &lt;br /&gt;
&lt;b&gt;Create Edmx file i.e EntityFramwork file&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-ebQ7GcSI9Hw/UCP_jmfcyeI/AAAAAAAADPI/PTfwI3ftPJ0/s1600/edmx.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="256" src="http://4.bp.blogspot.com/-ebQ7GcSI9Hw/UCP_jmfcyeI/AAAAAAAADPI/PTfwI3ftPJ0/s400/edmx.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&amp;nbsp;&lt;b&gt;Create connection with database&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-fM9M4MxcXH4/UCP_rd8r_PI/AAAAAAAADPU/Ty_qazw2Rm0/s1600/edmx1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="355" src="http://2.bp.blogspot.com/-fM9M4MxcXH4/UCP_rd8r_PI/AAAAAAAADPU/Ty_qazw2Rm0/s400/edmx1.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Select Table(s),view(s) and Stored procedure(s)&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/--oHMqOZOyx8/UCP_x-_TGrI/AAAAAAAADPg/Eq-fdTzJCiM/s1600/edmx2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="354" src="http://4.bp.blogspot.com/--oHMqOZOyx8/UCP_x-_TGrI/AAAAAAAADPg/Eq-fdTzJCiM/s400/edmx2.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Created EDMX file&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-GwifIFy25AI/UCP_8asIK3I/AAAAAAAADPs/IUehcqxPM4w/s1600/edmx3.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="237" src="http://3.bp.blogspot.com/-GwifIFy25AI/UCP_8asIK3I/AAAAAAAADPs/IUehcqxPM4w/s400/edmx3.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Use SqlFunction in query&lt;/b&gt;&lt;br /&gt;
Now after deisigning the enityframwork edmx file following is way to utilize the inbuilt sql server functions in Linq queries. &lt;/div&gt;&lt;pre class="brush: csharp"&gt;public List&amp;lt;person&amp;gt; SqlTest()
        {
            using (SchoolEntities se = new SchoolEntities())
            {
                var person = from p in se.People
                             where SqlFunctions.CharIndex("a", p.FirstName) == 1
                             select p;
                return person.ToList&amp;lt;person&amp;gt;();
            }
        }
&lt;/pre&gt;As you see in above linq query its find out all persons whose name starts with letter "a". This is easily achievable by &lt;i&gt;CharIndex&lt;/i&gt; function of sql server as you can see in query. This function is part of SqlFunction class avilable in .net framework.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;SqlFunction class inside&lt;/b&gt; &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;#region Assembly System.Data.Entity.dll, v4.0.30319
// C:\Program Files\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\Profile\Client\System.Data.Entity.dll
#endregion

using System;
using System.Collections.Generic;
using System.Data.Objects.DataClasses;

namespace System.Data.Objects.SqlClient
{
 // Summary:
    //     Provides common language runtime (CLR) methods that call functions in the
    //     database in LINQ to Entities queries.
    public static class SqlFunctions
    {
        ........list of other function that is supported by this class
        //
        // Summary:
        //     Returns the starting position of one expression found within another expression.
        //
        // Parameters:
        //   toSearch:
        //     The string expression to be searched.
        //
        //   target:
        //     The string expression to be found.
        //
        //   startLocation:
        //     The character position in toSearch where searching begins.
        //
        // Returns:
        //     The starting position of target if it is found in toSearch.
        [EdmFunction("SqlServer", "CHARINDEX")]
        public static int? CharIndex(string toSearch, string target, int? startLocation)
    }
}
&lt;/pre&gt;As you can see SqlFuction is static class and contains static methods which calls sql server inbuilt function.&lt;br /&gt;
Get more information about SqlFunction class and its method on msdn at : &lt;a href="http://msdn.microsoft.com/en-us/library/dd456858.aspx"&gt;SqlFunction&lt;/a&gt; &lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/08/call-sql-server-inbuilt-functions-using.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://4.bp.blogspot.com/-ebQ7GcSI9Hw/UCP_jmfcyeI/AAAAAAAADPI/PTfwI3ftPJ0/s72-c/edmx.jpg" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6712394284811592136</guid><pubDate>Thu, 02 Aug 2012 06:47:00 +0000</pubDate><atom:updated>2012-08-11T16:04:07.555-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Asp.Net</category><category domain="http://www.blogger.com/atom/ns#">Duplex</category><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">WCF</category><title>Responsive WCF service With ICallbackEventHandler Interface</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I am going to discuss about the development of the WCF(duplex) callback service which replay back to consumer i.e client of service and about &lt;i&gt;ICallbackEventHandler&lt;/i&gt; Interface implementation which provide response to the user on screen.&lt;br /&gt;
&lt;br /&gt;
Here I designed WCF service which is place order for client and reply back to client that order placed successfully or not. &lt;i&gt;ICallbackEventHandler&lt;/i&gt; interface implemented on page display response to client. Before I discuss more here is the screen that shows output&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Place Order&lt;/b&gt;&lt;a href="http://1.bp.blogspot.com/-ZEb7AYzhdEY/UAut6YAWgTI/AAAAAAAADNk/5ieDoi5koS0/s1600/wcf.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="150" src="http://1.bp.blogspot.com/-ZEb7AYzhdEY/UAut6YAWgTI/AAAAAAAADNk/5ieDoi5koS0/s640/wcf.jpg" width="640" /&gt;&lt;/a&gt;&lt;a href="http://1.bp.blogspot.com/-pz9_cGDb5eM/UAut6mCJ49I/AAAAAAAADNw/h27HLwYWczQ/s1600/wcf1.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-OGPKAGOhw-M/UAut6_aNaqI/AAAAAAAADN8/-m6PCRcyoRE/s1600/wcf2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;br /&gt;
&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;WCF service placing order&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-pz9_cGDb5eM/UAut6mCJ49I/AAAAAAAADNw/h27HLwYWczQ/s1600/wcf1.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="169" src="http://1.bp.blogspot.com/-pz9_cGDb5eM/UAut6mCJ49I/AAAAAAAADNw/h27HLwYWczQ/s640/wcf1.jpg" width="640" /&gt;&lt;/a&gt;&lt;a href="http://1.bp.blogspot.com/-ZEb7AYzhdEY/UAut6YAWgTI/AAAAAAAADNk/5ieDoi5koS0/s1600/wcf.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Order placed successful or not &lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-OGPKAGOhw-M/UAut6_aNaqI/AAAAAAAADN8/-m6PCRcyoRE/s1600/wcf2.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="148" src="http://2.bp.blogspot.com/-OGPKAGOhw-M/UAut6_aNaqI/AAAAAAAADN8/-m6PCRcyoRE/s640/wcf2.jpg" width="640" /&gt;&lt;/a&gt;&lt;a href="http://1.bp.blogspot.com/-pz9_cGDb5eM/UAut6mCJ49I/AAAAAAAADNw/h27HLwYWczQ/s1600/wcf1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
To accomplish this whole program get divide in two part &lt;br /&gt;
1) Design of callback WCF service &lt;br /&gt;
2) Design of WEB page with &lt;i&gt;ICallbackEventHandler&lt;/i&gt; interface to provide response on screen&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Design of callback WCF service &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Config file&lt;/i&gt;&lt;/b&gt; &lt;br /&gt;
You need to config WCF service as below to make service reliable(duplex) i.e send response back to client once task done.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;configuration&amp;gt;
  &amp;lt;system.servicemodel&amp;gt;
    &amp;lt;bindings&amp;gt;
      &amp;lt;wsdualhttpbinding&amp;gt;
        &amp;lt;binding bypassproxyonlocal="true" name="sampleBinding" usedefaultwebproxy="true"&amp;gt;
      &amp;lt;/binding&amp;gt;&amp;lt;/wsdualhttpbinding&amp;gt;
    &amp;lt;/bindings&amp;gt;
    &amp;lt;services&amp;gt;
      &amp;lt;service behaviorconfiguration="returnFaults" name="Service.DemoService"&amp;gt;
        &amp;lt;endpoint binding="wsDualHttpBinding" bindingconfiguration="sampleBinding" contract="Service.IDemoService"&amp;gt;
      &amp;lt;/endpoint&amp;gt;&amp;lt;/service&amp;gt;
    &amp;lt;/services&amp;gt;
    &amp;lt;behaviors&amp;gt;
      &amp;lt;servicebehaviors&amp;gt;
        &amp;lt;behavior name="returnFaults"&amp;gt;
          &amp;lt;servicedebug includeexceptiondetailinfaults="true"&amp;gt;
          &amp;lt;servicemetadata httpgetenabled="true"&amp;gt;
        &amp;lt;/servicemetadata&amp;gt;&amp;lt;/servicedebug&amp;gt;&amp;lt;/behavior&amp;gt;
      &amp;lt;/servicebehaviors&amp;gt;
    &amp;lt;/behaviors&amp;gt;
  &amp;lt;/system.servicemodel&amp;gt;
  &amp;lt;system.web&amp;gt;
    &amp;lt;compilation debug="true"&amp;gt;
  &amp;lt;/compilation&amp;gt;&amp;lt;/system.web&amp;gt;
&amp;lt;/configuration&amp;gt;&lt;/pre&gt;Thing to note in config file is&amp;nbsp;used protocol called "wsDualHttpBinding" that allows to create reliable session that means it allows to send response back to client who made call to service once task get completed.&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/system.servicemodel.wsdualhttpbinding.aspx"&gt;WSDualHttpBinding&lt;/a&gt; - A secure and interoperable binding that is designed for use with duplex service contracts that allows both services and clients to send and receive messages.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;WCF Service file&lt;/i&gt; &lt;/b&gt;&lt;br /&gt;
After creating or modifying you can code service file as below .&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;using System;
using System.ServiceModel;
using System.Collections.Generic;
using System.Threading;
using System.Runtime.Serialization;

namespace Service
{
&lt;/pre&gt;&lt;b&gt;&lt;i&gt;IDemoService&lt;/i&gt;&lt;/b&gt;- interface that is implemented in WCF service. whose method get called by application consuming wcf service.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[ServiceContract(CallbackContract = typeof(IClientCallBack))]
    public interface IDemoService
    {
        [OperationContract(IsOneWay = true)]
        void PlaceOrder(OrderItem item);
    }
&lt;/pre&gt;&lt;b&gt;&lt;i&gt;ServiceContractAttribute.CallbackContract &lt;/i&gt;&lt;/b&gt;- This attribute allows to set callback contract when the contract is a duplex contract i.e callback interface that get called by service to inform client.&lt;br /&gt;
So this allows client applications to listen for inbound operation calls that the server-side service application can send to client application which is independent from client activity. Callback contracts that have one-way operations represent calls from the service that the client can handle.&lt;br /&gt;
&lt;b&gt;&lt;i&gt;IClientCallBack&lt;/i&gt;&lt;/b&gt;- interface that is get implemented on the client side i.e by the application which is consuming the wcf service. Method of this interface get called from wcf service methods which is discussed below.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public interface IClientCallBack
    {
        [OperationContract(IsOneWay = true)]
        void ISOrerPlaceSuccessfully(bool issuccess, float total);
    }
&lt;/pre&gt;&lt;b&gt;&lt;i&gt;OrderItem&lt;/i&gt;&lt;/b&gt; - is datacontract class of wcf service.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;[DataContract]
    public class OrderItem
    {
        float price;
        string name;
        int qty;
        [DataMember]
        public float Price
        {
            get { return price; }
            set { price = value;}
        }

        [DataMember]
        public string Name
        {
            get { return name; }
            set { name = value; }
        }

        [DataMember]
        public int Quantity
        {
            get { return qty; }
            set { qty = value; }
        }
    }
&lt;/pre&gt;&lt;b&gt;&lt;i&gt;DemoService&lt;/i&gt;&lt;/b&gt; - Implement service contract interface.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public class DemoService : IDemoService
    {
        public void PlaceOrder(OrderItem item)
        {
            IClientCallBack callback = OperationContext.Current.GetCallbackChannel&amp;lt;IClientCallBack&amp;gt;();
            bool success = true;
            //process order 
            float total = item.Price * item.Quantity;
            callback.ISOrerPlaceSuccessfully(success, total);
        }
    }
}&lt;/pre&gt;&lt;b&gt;&lt;i&gt;PlaceOrder&lt;/i&gt;&lt;/b&gt; - method call the callback contract method &lt;i&gt;ISOrerPlaceSuccessfully&lt;/i&gt;.&lt;br /&gt;
&lt;b&gt;&lt;i&gt;OperationContext.Current&lt;/i&gt;&lt;/b&gt; -Gets the execution context for the current thread.&lt;br /&gt;
code uses the Current property and &lt;i&gt;GetCallbackChannel&lt;/i&gt;&lt;t&gt; method to create a channel back to the caller i.e to client from service method. one-way method allows service and client to communicate in both directions independently. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Design of WEB page with ICallbackEventHandler interface to provide response on screen&lt;/b&gt;&lt;/t&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;.ASPX file&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="WebClient.Default" EnableSessionState="True"%&amp;gt;

&amp;lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&amp;gt;
&amp;lt;html xmlns="http://www.w3.org/1999/xhtml"&amp;gt;
&amp;lt;head runat="server"&amp;gt;
    &amp;lt;title&amp;gt;&amp;lt;/title&amp;gt;
&amp;lt;/head&amp;gt;
&amp;lt;body id="formBody" runat="server" &amp;gt;
    &amp;lt;form id="form1" runat="server"&amp;gt;
    &amp;lt;div style="text-align:center"&amp;gt;
      &amp;lt;h1&amp;gt;Place Order&amp;lt;/h1&amp;gt;
    &amp;lt;/div&amp;gt;
    &amp;lt;div&amp;gt;
        &amp;lt;table&amp;gt;
           &amp;lt;tr&amp;gt;
             &amp;lt;td&amp;gt;&amp;lt;asp:Label ID="lblItemName" runat="server" Text="Label"&amp;gt;Item Number :&amp;lt;/asp:Label&amp;gt;&amp;lt;/td&amp;gt;
             &amp;lt;td&amp;gt;&amp;lt;asp:Label ID="lblItemValue" runat="server" Text="Label"&amp;gt;Test&amp;lt;/asp:Label&amp;gt;&amp;lt;/td&amp;gt;
           &amp;lt;/tr&amp;gt;
           &amp;lt;tr&amp;gt;
             &amp;lt;td&amp;gt;&amp;lt;asp:Label ID="Label1" runat="server" Text="Label"&amp;gt;Price :&amp;lt;/asp:Label&amp;gt;&amp;lt;/td&amp;gt;
             &amp;lt;td&amp;gt;&amp;lt;asp:Label ID="Label2" runat="server" Text="Label"&amp;gt;500&amp;lt;/asp:Label&amp;gt;&amp;lt;/td&amp;gt;
           &amp;lt;/tr&amp;gt;
           &amp;lt;tr&amp;gt;
             &amp;lt;td&amp;gt;&amp;lt;asp:Label ID="Label3" runat="server" Text="Label"&amp;gt;Qunatity :&amp;lt;/asp:Label&amp;gt;&amp;lt;/td&amp;gt;
             &amp;lt;td&amp;gt;&amp;lt;asp:TextBox ID="txtQunatity" runat="server" &amp;gt;&amp;lt;/asp:TextBox&amp;gt;&amp;lt;/td&amp;gt;
           &amp;lt;/tr&amp;gt;
        &amp;lt;/table&amp;gt;
        &amp;lt;asp:Button ID="Button1" runat="server" Text="Place Order" OnClick="Button1_Click" /&amp;gt;
        &amp;lt;asp:Label ID="lblMsg" runat="server"&amp;gt;&amp;lt;/asp:Label&amp;gt;&amp;lt;/div&amp;gt;
    
    &amp;lt;/form&amp;gt;
&amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;.Cs file &lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebClient.DemoService;
using System.ServiceModel;
using System.Threading;

namespace WebClient
{
&lt;/pre&gt;&lt;b&gt;&lt;i&gt;Implementation of Client callback interface&lt;/i&gt;&lt;/b&gt; - here all method declare in service as part of callback contract get implemented. This method is get called by the service method once task done on service side.&lt;br /&gt;
&lt;pre&gt;public class CallBack : WebClient.DemoService.IDemoServiceCallback
    {
        public string Message
        {
            get;set;
        }
        public void ISOrerPlaceSuccessfully(bool issuccess, float total)
        {
            Thread.Sleep(5000);
            if (issuccess)
                this.Message = "Order with total of : " + total + " placed successfully";
            else
                this.Message = "Order with total of : " + total + " failed to place";
        }
    }
&lt;/pre&gt;&lt;b&gt;&lt;i&gt;ISOrerPlaceSuccessfully &lt;/i&gt;&lt;/b&gt;- is callback method which is get called back from the placeorder method of service. Once response is arrived Message property value get updated which is used to show the order stats on user screen.&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Note&lt;/i&gt; &lt;/b&gt;- Thread.Sleep is used in code just for the delay/demo purpose i.e to show the how it actually works when longer process get called on service. Remove it when make use in project.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;ICallbackEventHandler Interface&lt;/i&gt;&lt;/b&gt; - Used to indicate that a control can be the target of a callback event on the server.&lt;br /&gt;
The &lt;i&gt;ICallbackEventHandler&lt;/i&gt; is a wrapper on &lt;i&gt;XMLHTTP&lt;/i&gt;. So that it allow to call the serverside method without any postback and there is no need to wirte any javascript/jquery for making ajax call all things get handle this interface in .net framework. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public partial class Default : System.Web.UI.Page, ICallbackEventHandler
    {
        static CallBack callback;
        DemoServiceClient client;
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            setupClientSideCallback();
            callback = new CallBack();
            InstanceContext ic = new InstanceContext(callback);
            client = new DemoServiceClient(ic);
            OrderItem item = new OrderItem();
            item.Name = "Test";
            item.Price = 12;
            item.Quantity = Convert.ToInt32(txtQunatity.Text);
            lblMsg.Text = "Placing Order...";
            client.PlaceOrder(item);
        }
&lt;/pre&gt;Here in above code callback is variable of type Callback clas which is static because on the order pace button get clicked value of callback is remain as it is i.e its not get created again for later on use in &lt;i&gt;GetCallbackResult&lt;/i&gt; method which is discussed below.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;OnCallback &lt;/i&gt;&lt;/b&gt;is method defined at client side which is used to call back once the clientscript register&amp;nbsp;by serverside code&amp;nbsp;and eventArg is a variable defined at the client side which holds the parameter value.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;protected void setupClientSideCallback()
        {
           string ScriptRef = this.ClientScript.GetCallbackEventReference(this, "'" + 0 + "'", "OnCallback", "'" + lblMsg.ClientID + "'");
            formBody.Attributes.Add("onload", ScriptRef);
            string script = "&amp;lt;script language="javascript" type="text/javascript"&amp;gt;
 " +
                         " function getResponse() " +
                         " { " + ScriptRef + " } " +
                         " function OnCallback(Result,Context) " +
                         " { " +
                         " var lbl=document.getElementById(Context); " +
                          " lbl.innerText=Result ; " +
                          " setTimeout(getResponse, 1000); " +
                          " } " +
                         " 
&amp;lt;/script&amp;gt; ";
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "ClientCallback", script);

        }&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Javascript code&lt;/i&gt;&lt;/b&gt; - get register when placeorder button get clicked. After that to check the response arrived from the wcf service or not it makes call at regular interval by using &lt;i&gt;setTimeout&lt;/i&gt; function. So it works&amp;nbsp;like timer which execute set of code at regular interval. &lt;br /&gt;
&lt;br /&gt;
The &lt;i&gt;ICallbackEventHandler&lt;/i&gt; interface has two methods which required to be implemented in the page.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;i&gt;RaiseCallbackEvent &lt;/i&gt;&lt;/b&gt;- This event is called when the call from client side (Javascript)i.e from browser to server. This is the event to handle the call back handler. Here eventArgs is a parameter which is passed from client side. &lt;br /&gt;
&lt;b&gt;&lt;i&gt;GetCallbackResult &lt;/i&gt;&lt;/b&gt;- This methos returns the result of the callback event to client side i.e from serverside to browser.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;string ICallbackEventHandler.GetCallbackResult()
        {
            if (callback!=null &amp;amp;&amp;amp; callback.Message != null)
            {
                return  callback.Message;
            }
            return "Placing Order..." ;
        }

        string eventArgument;

        void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
        {
            this.eventArgument = eventArgument;
        } 
    }
}
&lt;/pre&gt;&lt;b&gt;Summary&lt;/b&gt;&lt;br /&gt;
WCF reliable(duplex) service useful to inform the cosumer of service i.e client of service that task completed or not by calling the consumer i.e client from service. This kind of suff useful when we are creating modules where payment of order take place as I did in my implementation.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Note&lt;/b&gt; &lt;br /&gt;
I cannot upload code over here but if you want code of the same mail me at &lt;a href="mailto:pranayamr@gmail.com"&gt;pranayamr@gmail.com&lt;/a&gt; or just follow the post step and paste code in your project. &lt;br /&gt;
Javascript code is currenly working on IE only which will be&amp;nbsp;modified soon.&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/08/responsive-wcf-service-with.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-ZEb7AYzhdEY/UAut6YAWgTI/AAAAAAAADNk/5ieDoi5koS0/s72-c/wcf.jpg" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-3146496853560399456</guid><pubDate>Thu, 26 Jul 2012 18:55:00 +0000</pubDate><atom:updated>2012-07-26T14:55:09.446-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><category domain="http://www.blogger.com/atom/ns#">LINQ</category><title>Count() and Count property</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this small post I am going to discuss about the &lt;i&gt;Count&lt;/i&gt; property and &lt;i&gt;Count()&lt;/i&gt; method that used to return count of number of element in collection.   &lt;br /&gt;
&lt;b&gt;&lt;i&gt;Count&lt;/i&gt; property&lt;/b&gt;&lt;br /&gt;
Each collection object which is inherited from &lt;i&gt;ICollection&lt;/i&gt;&lt;i&gt;&amp;lt;T&amp;gt;&lt;/i&gt; Interface has count property which returns number of element in collection.&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Count()&lt;/i&gt; Function&lt;/b&gt;&lt;br /&gt;
But the things change when you make use of &lt;i&gt;System.Linq &lt;/i&gt;namespace in you code. when you make use of this namespace you get &lt;i&gt;Count()&lt;/i&gt;&lt;t&gt; method which also returns you number of element in you collection. But the point to not here is &lt;i&gt;Count()&lt;/i&gt; is extestion method of &lt;i&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/i&gt; class.  Check the following images  &lt;br /&gt;
&lt;b&gt;Without using Linq namespace&lt;/b&gt; &lt;/t&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-jR8erBuBLHI/UBFSp8F00uI/AAAAAAAADOQ/-MdMEYAL2jg/s1600/without%2Blinq.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="201" src="http://3.bp.blogspot.com/-jR8erBuBLHI/UBFSp8F00uI/AAAAAAAADOQ/-MdMEYAL2jg/s640/without%2Blinq.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;b&gt;With Using Linq namespace&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-B8wQZUajy78/UBFSxQacfkI/AAAAAAAADOc/td6LoClT5dY/s1600/with%2Blinq.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="201" src="http://1.bp.blogspot.com/-B8wQZUajy78/UBFSxQacfkI/AAAAAAAADOc/td6LoClT5dY/s640/with%2Blinq.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/i&gt; Source after query&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-rbnrcCo93rs/UBFTCBtFaNI/AAAAAAAADOo/YLukv3UYXQQ/s1600/when%2Bsource%2Btype%2Bis%2Benumerable.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="288" src="http://1.bp.blogspot.com/-rbnrcCo93rs/UBFTCBtFaNI/AAAAAAAADOo/YLukv3UYXQQ/s640/when%2Bsource%2Btype%2Bis%2Benumerable.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;After Converting Source to &lt;i&gt;ICollection&amp;lt;T&amp;gt;&lt;/i&gt; type &lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-KLQmXBQuo6Q/UBFTMQRtFGI/AAAAAAAADO0/rKkCKyd-0Jg/s1600/after%2Bconverting%2Bsource%2Bto%2BIcollection%2Bimplemented%2Bobject.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="235" src="http://2.bp.blogspot.com/-KLQmXBQuo6Q/UBFTMQRtFGI/AAAAAAAADO0/rKkCKyd-0Jg/s640/after%2Bconverting%2Bsource%2Bto%2BIcollection%2Bimplemented%2Bobject.JPG" width="640" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
Code on which I tested &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;List&amp;lt;string&amp;gt; lst = new List&amp;lt;string&amp;gt;() { "abc", "def" };
int a = lst.Count;
var b = lst.Where(x =&amp;gt; x == "abc").Count();
List&amp;lt;string&amp;gt; ls = lst.Where(x =&amp;gt; x == "abc").ToList&amp;lt;string&amp;gt;();
a= ls.Count;
&lt;/pre&gt;If you are using &lt;i&gt;Count()&lt;/i&gt; method on source which implements &lt;i&gt;ICollection&amp;lt;T&amp;gt;&lt;/i&gt; interface than extension method make use of the &lt;i&gt;Count&lt;/i&gt; property of it and returns no of element.  If the source not implemented from the &lt;i&gt;ICollection&amp;lt;T&amp;gt;&lt;/i&gt; than it do perform the operation on the element of source and return count of it.  &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Point to Note   &lt;/b&gt;&lt;br /&gt;
- As per MSDN : Retrieving the value of &lt;i&gt;Count &lt;/i&gt;property is an O(1) operation. &lt;br /&gt;
- &lt;i&gt;Count()&lt;/i&gt; function perform the operation and return value, so its slower than count property.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclustion &lt;/b&gt;&lt;br /&gt;
Although its stated that &lt;i&gt;Count()&lt;/i&gt; function make use of count property if the source implemented from &lt;i&gt;ICollection&amp;lt;T&amp;gt;&lt;/i&gt; than use cont property, its better to use count property directly if source implemented &lt;i&gt;ICollection&amp;lt;T&amp;gt;&lt;/i&gt; otherwise go for &lt;i&gt;Count()&lt;/i&gt; get number of element in source.&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/07/count-and-count-property.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://3.bp.blogspot.com/-jR8erBuBLHI/UBFSp8F00uI/AAAAAAAADOQ/-MdMEYAL2jg/s72-c/without%2Blinq.JPG" height="72" width="72" /><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-9045178510541969349</guid><pubDate>Tue, 24 Jul 2012 19:25:00 +0000</pubDate><atom:updated>2012-07-24T15:25:45.138-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Enhance String type to get Converted In Given Type</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;b&gt;Problem &lt;/b&gt;&lt;br /&gt;
Recently I was working on the project where I need to read the excel file data and have to convert data of it in strong entity which is consist of number of property. For this I know the sequence of the data in excel file and name &amp;amp; type of property of the entity which is going to store the value. But the real problem is I need to convert the string value in property type.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
One of the solution to this is create function and pass the type &amp;amp; string value which &lt;br /&gt;
return data in type which is passed. Below is implementation function&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static T ConvertData&amp;lt;T&amp;gt;(this string s)
{
     if(!sting.IsNullOrEmpty(s))
     {
        if (typeof(T) == typeof(System.Decimal))
        {
           return (T)(object)Convert.ToDecimal(s);
        }
     }
     //same code get replicated for int, float etc. 
     return default(T);
}
&lt;/pre&gt;In above code  I created on generic extension method for string type. Function convert string type to the type I want. &lt;br /&gt;
&lt;i&gt;&lt;b&gt;Cons&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;In above implementation I written code for Decimal type but same code I have to replicate for other types also i.e for int, float etc.&lt;/li&gt;
&lt;li&gt;As you see in code after converting data in given type I again need to reconvert into object and than into type T again. This also add overhead of type casting.&lt;/li&gt;
&lt;li&gt;Code is become long and unclear.&lt;/li&gt;
&lt;/ul&gt;&lt;br /&gt;
So to make code clean , clear and easy to understand. I fond one method in C#.net which is &lt;i&gt;Convert.ChangeType&lt;/i&gt; which helps me to create the method i want easily.&lt;br /&gt;
Below is my Simpler and easy solution &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static T ConvertData&amp;lt;T&amp;gt;(this string s)
{
     if(!sting.IsNullOrEmpty(s))
     {
         return (T)Convert.ChangeType(s, typeof(T),null);
     }
     return default(T);
}
&lt;/pre&gt;So in above solution I just need to write one line of the code which do the task for me. &lt;br /&gt;
Actual syntax of method is &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static Object ChangeType(
 Object value,
 Type conversionType,
 IFormatProvider provider
)
&lt;/pre&gt;As you can see in syntax third parameter is provider which is null in my case but you can pass the formater by creating as you need.&lt;br /&gt;
Now following code is just show how to use this method in code i.e ConvertData method&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;string s = "123";
int a = s.ConvertData&amp;lt;int&amp;gt;();
&lt;/pre&gt;So this method can be used any project and also fit in number of requirement.&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/07/enhance-string-type-to-get-converted-in.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-1345418661483171711</guid><pubDate>Thu, 19 Jul 2012 19:28:00 +0000</pubDate><atom:updated>2012-07-19T15:28:45.103-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">reflection</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Extending Enum to return attached string</title><description>No of time there is requirement of getting string of Enum value to display purpose or to perform other task. So to deal with this requirement I wrote one extension function that get the string attached with the enum value. &lt;br /&gt;
&lt;b&gt;Note :&lt;/b&gt; here attached string value is the attribute that is attached with each enum value that you are creating in enum variable.&lt;br /&gt;
&lt;br /&gt;
Following is extension function to get string attached with enum.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;public static class MyExtensions
{
   public static string GetEnumDescription(this Enum value)
   {            
         FieldInfo fi = value.GetType().GetField(value.ToString());

         object[] attributes = fi.GetCustomAttributes(true);

         if (attributes != null &amp;&amp;
            attributes.Length &gt; 0)
                return ((DescriptionAttribute) attributes[0]).Description;
         else
                return value.ToString();
    }
}
&lt;/pre&gt;The code above is making use of the reflection feature of .net framework. With the help of reflection it first get the information about the field and than get the attribute attached with that field. Attribute attached with enum value is DescriptionAttribute so code convert attribute object to DescriptionAttribute and return string attached with it. If there is no attribute attached with enum value it returns the interger value of enum as string.&lt;br /&gt;
&lt;br /&gt;
Note : Attribute is metadata attached with the type you can attache metadata with class, function , property etc. Read More: &lt;a href="http://msdn.microsoft.com/en-us/library/z0w1kczw%28v=vs.80%29.aspx"&gt;Attributes (C# Programming Guide)&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
Following is simple program that is making use of extension function and to display the string attached with the enum value.&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;class Program
    {
        public enum WeekDay
        {
            [Description("Monday")]
            Monday,
            [Description("Tuesday")]
            Tuesday
        }

        static void Main(string[] args)
        {
            string str = (WeekDay.Monday).GetEnumDescription();
            Console.WriteLine(str);
            Console.ReadLine();
        }
    }
&lt;/pre&gt;In above code there is enum create with the name WeekDay and as per the requirement it require to attache attribute with the each enum value to function to work properly if no attribute attached with enum value than function return value of enum i.e interger value associated with the enum.&lt;br /&gt;
&lt;br /&gt;
So when code in "Main function" get executed call to function "GetEnumDescription" it return "Monday" as output on the console window which is associated with enum value.</description><link>http://pranayamr.blogspot.com/2012/07/extending-enum-to-return-attached-string.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-8812543631489881623</guid><pubDate>Tue, 17 Jul 2012 19:40:00 +0000</pubDate><atom:updated>2012-07-19T15:27:34.194-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">Sql Server</category><category domain="http://www.blogger.com/atom/ns#">Stored Procedure</category><category domain="http://www.blogger.com/atom/ns#">Beginner</category><category domain="http://www.blogger.com/atom/ns#">.net</category><category domain="http://www.blogger.com/atom/ns#">Visual Studio</category><category domain="http://www.blogger.com/atom/ns#">TypeDataSet</category><title>Design TypeDataSet from Storedprocedure using temptable</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;I found one problem recently while designing TypeDataset in VisualStudio using storedproceudre which is making use of temporary table to get result.&lt;br /&gt;
&lt;br /&gt;
Here is detail of the it what I did and how I resolved the issue.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 1:&lt;/b&gt; Created Procedure with Temporary table&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;create PROCEDURE [dbo].[GetData]
AS
begin
   create TABLE #MyTable  (
  ID int,
  Name nvarchar(50) )

 INSERT INTO #MyTable (ID, Name)
 SELECT  PersonID, FirstName + ' ' + LastName
 FROM  dbo.Person
 
 SELECT ID,
  Name 
 FROM #MyTable
end
&lt;/pre&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 2:&lt;/b&gt; Add TableAdapter in the design view of TypeDataSet and create database connection&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-DbUfg9X6jKA/UARX9Ut8ObI/AAAAAAAADMM/m9rbnfAQEic/s1600/pr1.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="236" src="http://4.bp.blogspot.com/-DbUfg9X6jKA/UARX9Ut8ObI/AAAAAAAADMM/m9rbnfAQEic/s400/pr1.jpg" width="400" /&gt;&lt;/a&gt;&lt;a href="http://4.bp.blogspot.com/-jm7NZnFlsGU/UARX-ihzEuI/AAAAAAAADM8/0iXRzL4HN90/s1600/pr5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt; &lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 3:&lt;/b&gt; Create Procedure or Select Existing procedure&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-AmPwTfwajxU/UARX9pV3HoI/AAAAAAAADMY/7XW0rx7qumE/s1600/pr2.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="316" src="http://4.bp.blogspot.com/-AmPwTfwajxU/UARX9pV3HoI/AAAAAAAADMY/7XW0rx7qumE/s400/pr2.jpg" width="400" /&gt;&lt;/a&gt;&lt;a href="http://4.bp.blogspot.com/-DbUfg9X6jKA/UARX9Ut8ObI/AAAAAAAADMM/m9rbnfAQEic/s1600/pr1.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Step 4 :&lt;/b&gt; Select Procedure that I created already&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://3.bp.blogspot.com/-iqMz5nsMUZ4/UARX9wgZmyI/AAAAAAAADMk/YnhSwI9TiZs/s1600/pr3.jpg" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="313" src="http://3.bp.blogspot.com/-iqMz5nsMUZ4/UARX9wgZmyI/AAAAAAAADMk/YnhSwI9TiZs/s400/pr3.jpg" width="400" /&gt;&lt;/a&gt;&lt;a href="http://4.bp.blogspot.com/-AmPwTfwajxU/UARX9pV3HoI/AAAAAAAADMY/7XW0rx7qumE/s1600/pr2.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;/a&gt;&lt;/div&gt;Note : here it's not displaying DataColumn of select statement related to proceudre&lt;br /&gt;
&lt;b&gt;&lt;br /&gt;
&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Step 5 :&lt;/b&gt; Click on finish it display that in valid object #table&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-d3Y8j5nUv9o/UARX-IzDHcI/AAAAAAAADM0/qLSTaQqQoKM/s1600/pr4.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="314" src="http://2.bp.blogspot.com/-d3Y8j5nUv9o/UARX-IzDHcI/AAAAAAAADM0/qLSTaQqQoKM/s400/pr4.jpg" width="400" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
so it doesn't able to create tableadapter for procedure and display like this&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://2.bp.blogspot.com/-fbW-AKEJ2fI/UARYMc1CS5I/AAAAAAAADNU/xcHfKc1f0F0/s1600/pr5.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="123" src="http://2.bp.blogspot.com/-fbW-AKEJ2fI/UARYMc1CS5I/AAAAAAAADNU/xcHfKc1f0F0/s400/pr5.jpg" width="240" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;br /&gt;
&lt;b&gt;Solution&lt;/b&gt;&lt;br /&gt;
To resolve this issue you can try one of the following solution , I tried first solution because its easy and not require to change in my existing storedprocedure code&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Solution 1&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
Just add below line at top of the procedure after begin statement  &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;SET FMTONLY OFF&lt;/pre&gt;This will resolve the issue and allow to create tableadapter easily without any error. So procedure will be &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;create PROCEDURE [dbo].[GetData]
AS
begin
  SET FMTONLY OFF
   //code of the procedure as above
end
&lt;/pre&gt;&lt;i&gt;&lt;b&gt;Solution 2&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
To try this solution just create table variable instead of temporary table in procedure. So procedure will be &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;create PROCEDURE [dbo].[GetData]
AS
begin
  DECLARE @MyTable TABLE (
  ID int,
  Name nvarchar(50) )

 INSERT INTO @MyTable (ID, Name)
 SELECT  PersonID, FirstName + ' ' + LastName
 FROM  dbo.Person
 
 SELECT ID,
  Name 
 FROM @MyTable
end
&lt;/pre&gt;&lt;br /&gt;
After trying the above solution tableadapter on XSD file will be like this &lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://4.bp.blogspot.com/-Jn5yYXCNS1c/UARYFG4V_2I/AAAAAAAADNI/gmhc1fnD2xg/s1600/pr6.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="132" src="http://4.bp.blogspot.com/-Jn5yYXCNS1c/UARYFG4V_2I/AAAAAAAADNI/gmhc1fnD2xg/s400/pr6.jpg" width="212" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/07/design-typedataset-from-storedprocedure.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://4.bp.blogspot.com/-DbUfg9X6jKA/UARX9Ut8ObI/AAAAAAAADMM/m9rbnfAQEic/s72-c/pr1.jpg" height="72" width="72" /><thr:total>0</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6764490666127121940</guid><pubDate>Fri, 06 Jul 2012 20:01:00 +0000</pubDate><atom:updated>2012-07-06T16:01:41.861-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">SilverLight</category><category domain="http://www.blogger.com/atom/ns#">RAD Control</category><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Align Text in Autogenerated Column of Rad Silverlight Girdview and Silverlight Gridview</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;In this post I am going to show how you can align data in autogenrated columns cell of Silverlight gridview and also of Rad Control Silverlight Gridview.&lt;br /&gt;
In both of the below Example of Gridview I want to align the numeric data left in my cell and other except numeric remain in same format. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;RAD Silverlight Gridview &lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;XAML code of Silverlight Gridview&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;telerik:RadGridView&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="clubsGrid" 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ItemsSource="{Binding Clubs}"
&amp;nbsp;AutoGeneratingColumn="clubsGrid_AutoGeneratingColumn"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Margin="5"&amp;gt;
&amp;lt;/telerik:RadGridView&amp;gt;
&lt;/pre&gt;Thing to note down here in XAML code is I register &lt;i&gt;AutoGeneratingColumn =&lt;/i&gt;&lt;br /&gt;
&lt;i&gt;"clubsGrid_AutoGeneratingColumn" &lt;/i&gt;event which is get called when Auto columns get generated for gridview. &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;private void clubsGrid_AutoGeneratingColumn(object sender, GridViewAutoGeneratingColumnEventArgs e)
{
 GridViewDataColumn column = e.Column as GridViewDataColumn;
        if (column.DataType == typeof(int)
           || column.DataType == typeof(decimal)
           || column.DataType == typeof(float)
                )
       {
           column.TextAlignment = TextAlignment.Right;
       }
 }
&lt;/pre&gt;As you see in above code I attached event called AutoGeneratingColumn on gridview control and checking DataType of each column which in turn check the datatype of the property which going to be attached with that column. So when the DataType is int or decimal or float I set TextAlignment propery of column to Right so display numeric value in right.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-mTCz5c3UthI/T_aOfGPIRQI/AAAAAAAADL8/bJrAKacd-0o/s1600/rad.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-mTCz5c3UthI/T_aOfGPIRQI/AAAAAAAADL8/bJrAKacd-0o/s1600/rad.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;So the output shows the column with numeric value "StadiumCapacity" is align to right.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Silvelight SDK Gridview control&lt;/b&gt;&lt;br /&gt;
There are two way to achieve this in Silverlight gridview&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 1) Setting cell style from code behind file but creating Style &lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 2) Setting cell style from code behind file but using resource&lt;b&gt;&lt;i&gt;&amp;nbsp;&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&lt;i&gt;XAML code of Silverlight Gridview&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;lt;sdk:DataGrid&amp;nbsp;&amp;nbsp; IsReadOnly="True" 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Name="mysGrid" 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; AutoGeneratingColumn="DataGrid_AutoGeneratingColumn"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ItemsSource="{Binding Clubs, Mode=OneWay}"&amp;gt;
&amp;lt;/sdk:DataGrid&amp;gt;
&lt;/pre&gt;Same as RAD Gridview here also wrote AutoGeneratingColumn="DataGrid_AutoGeneratingColumn" which take care of Autogenerated coulmn.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;First Way : Creating Sytle&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;&amp;nbsp;private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
 {
    if (e.PropertyType == typeof(int)
        || e.PropertyType == typeof(decimal)
        || e.PropertyType == typeof(float)
       )
    {
        var rightCellStyle = new Style(typeof(DataGridCell)); 
               
        rightCellStyle.Setters.Add(new Setter(
             Control.HorizontalContentAlignmentProperty,
             HorizontalAlignment.Right));

        DataGridBoundColumn obj = e.Column as DataGridBoundColumn;
        obj.CellStyle = rightCellStyle;
     }&lt;/pre&gt;&lt;pre class="brush: csharp"&gt;}
&lt;/pre&gt;As you see in above code same as RAD gridview control here e.PropertyType used to check the type of the autogenerated column but the change over here is need to create cell style and than assing the style to CellStyle property of gridview column.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Second Way : Using Resource &lt;/b&gt;&lt;br /&gt;
In this solution you need to register the style for the gridview cell as shown below and than you can use this to assign to CellStyle.&lt;br /&gt;
&lt;b&gt;&lt;i&gt;Resource in App.XAML&lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre&gt;&amp;nbsp; &amp;lt;Style x:Key="RightCellStyle" TargetType="sdk:DataGridCell"&amp;gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Setter Property="HorizontalContentAlignment" Value="Right" /&amp;gt;
&amp;nbsp; &amp;lt;/Style&amp;gt;
&lt;/pre&gt;&lt;b&gt;&lt;i&gt;CodeBehind file &lt;/i&gt;&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;private void DataGrid_AutoGeneratingColumn(object sender, DataGridAutoGeneratingColumnEventArgs e)
{
    if (e.PropertyType == typeof(int)
        || e.PropertyType == typeof(decimal)
        || e.PropertyType == typeof(float)
       )
       {
           DataGridBoundColumn obj = e.Column as DataGridBoundColumn;
           var rightCellStyle = Application.Current.Resources["RightCellStyle"] as Style;
           obj.CellStyle = rightCellStyle;
       }
}
&lt;/pre&gt;Now in this code you dont require to create any style you just need to fetch the resource that you register in the App.XAML file and need to convert in Style.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Output&lt;/b&gt;&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;&lt;a href="http://1.bp.blogspot.com/-4VwmM6YY1VM/T_aOVD5gYMI/AAAAAAAADLw/wZI-7Qs0h9k/s1600/Normal.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://1.bp.blogspot.com/-4VwmM6YY1VM/T_aOVD5gYMI/AAAAAAAADLw/wZI-7Qs0h9k/s1600/Normal.JPG" /&gt;&lt;/a&gt;&lt;/div&gt;So the output shows the column with numeric value "StadiumCapacity" is align to right.&lt;br /&gt;
&lt;b&gt;Note :&lt;/b&gt; in both the way output remain same. &lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/07/align-text-in-autogenerated-column-of.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-mTCz5c3UthI/T_aOfGPIRQI/AAAAAAAADL8/bJrAKacd-0o/s72-c/rad.JPG" height="72" width="72" /><thr:total>2</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-6320972736939598469</guid><pubDate>Sun, 17 Jun 2012 15:59:00 +0000</pubDate><atom:updated>2012-07-05T14:58:34.830-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><title>C# State machine - Yield</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;i&gt;Yield&lt;/i&gt; keyword introduced in C#2.0. &lt;i&gt;Yield &lt;/i&gt;keyword allow to create state machine and allow to iterate through the collection of objects one by one.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;yield &lt;/i&gt;is a contextual keyword used in iterator methods in C#. &lt;i&gt;yield &lt;/i&gt;use like following in iterator block&lt;br /&gt;
&lt;pre  class="brush: csharp"&gt;public IEnumerable methodname(params)
{
      foreach(type element in listofElement)
      {
         ...code for processing 
         yield return result;
      }
}
&lt;/pre&gt;Note : here &lt;i&gt;IEnumerable&lt;/i&gt; can be replace by &lt;i&gt;IEnumerable&amp;lt;T&amp;gt;&lt;/i&gt;. &lt;br /&gt;
What&amp;nbsp;&lt;i&gt;yield&lt;/i&gt; keyword does ? - "When you process the collection by this keyword in iterator block. It pause the execution return proceeded&amp;nbsp;&amp;nbsp;element or the current element of the collection. And when you call it again it start execution with the next element which in turn become current element for that call. This thing get continue till it reach the last element of collection."&lt;br /&gt;
&lt;br /&gt;
Now I am going to show how you can gain some performance when make use of &lt;i&gt;yield&lt;/i&gt; keyword.&lt;br /&gt;
In this example I am checking each &lt;i&gt;datarow &lt;/i&gt;of the &lt;i&gt;datatable&lt;/i&gt; weather it is empty or not. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Code With Yield Keyword&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;static void Main(string[] args)
{
     int[] arr = new int[] { 1, 2, 3 };

     DataTable table = new DataTable();
     table.Columns.Add("ItemName", typeof(string));
     table.Columns.Add("Quantity", typeof(int));
     table.Columns.Add("Price", typeof(float));
     table.Columns.Add("Process", typeof(string));
     //
     // Here we add five DataRows.
     //
     table.Rows.Add("Indocin", 2, 23);
     table.Rows.Add("Enebrel", 1, 10);
     table.Rows.Add(null, null, null);
     table.Rows.Add("Hydralazine", 1, null);
     table.Rows.Add("Combivent", 3, 5);
     table.Rows.Add("Dilantin", 1, 6);

     foreach (DataRow dr in GetRowToProcess(table.Rows))
     {
         if (dr != null)
         {                    
            dr["Process"] = "Processed";
            Console.WriteLine(dr["ItemName"].ToString()&amp;nbsp;
+ dr["Quantity"].ToString() + " : " + dr["Process"].ToString());
            //bool test = dr.ItemArray.Any(c =&amp;gt; c == DBNull.Value);
         }
      }
      Console.ReadLine();
}
private static IEnumerable&amp;lt;datarow&amp;gt;GetRowToProcess(DataRowCollection                                                         dataRowCollection)
{
     foreach (DataRow dr in dataRowCollection)
     {
          bool isempty = dr.ItemArray.All(x =&amp;gt; x == null ||&amp;nbsp;
(x!= null &amp;amp;&amp;amp; string.IsNullOrWhiteSpace(x.ToString())));

          if (!isempty)
          {
             yield return dr;
             //dr["Process"] = "Processed";
          }
          else
          {
             yield return null;
             //dr["Process"] = " Not having data ";
          }
          //yield return dr;
     }
}
&lt;/pre&gt;&lt;b&gt;Code Without Yield Keyword&lt;/b&gt;&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;private static IList&amp;lt;datarow&amp;gt; GetRowToProcess(DataRowCollection dataRowCollection)
{
    List&amp;lt;datarow&amp;gt; procedeedRows = new List&amp;lt;datarow&amp;gt;&lt;datarow&gt;();
    foreach (DataRow dr in dataRowCollection)
    {
        bool isempty = dr.ItemArray.All(x =&amp;gt; x == null ||&amp;nbsp;&lt;/datarow&gt;
&lt;datarow&gt;                           (x!= null &amp;amp;&amp;amp; string.IsNullOrWhiteSpace(x.ToString())));

        if (!isempty)
        {
          procedeedRows.Add(dr);
        }
     }
     return procedeedRows;
 }

static void Main(string[] args)
{
   //code as above function to create datatable 
   List&amp;lt;datarow&amp;gt; drs= GetRowToProcess(table.Rows);
   foreach (DataRow dr in drs)
   {
     //code to process the rows 
   } 
}
&lt;/datarow&gt;&lt;/pre&gt;&lt;br /&gt;
&lt;b&gt;Now Difference between two code&lt;/b&gt;&lt;br /&gt;
&lt;i&gt;&lt;b&gt;In code (Code without yield keyword)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
in this code there is extra list is get created which point to the rows which is matching the condition and than there is loop for processing each row.&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Disadvantage&lt;/b&gt;&lt;/i&gt; with this code is extra list is get created which occupies the extra space i.e memory as well as slow down the code.&lt;br /&gt;
&lt;i&gt;&lt;b&gt;In code (Code with yield keyword)&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
in this there no extra list is get created , with help yield one row at a time which is matching condition is get processed.&lt;br /&gt;
Advantage of the code is there is no extra list is get created and also it doesn't cause any performance problem.&lt;br /&gt;
&lt;br /&gt;
Following example of linq with the &lt;i&gt;yield &lt;/i&gt;keyword &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;void Main()
{
   // This uses a custom 'Pair' extension method, defined below.
   List&amp;lt;string&amp;gt; list1 = new List&amp;lt;string&amp;gt;()
 {
     "Pranay",
     "Rana",
     "Hemang",
     "Vyas"
 };
   IEnumerable&amp;lt;string&amp;gt;&lt;string&gt;  query = list1.Select (c =&amp;gt; c.ToUpper())
  .Pair()         // Local from this point on.
  .OrderBy (n =&amp;gt; n.length);
}

public static class MyExtensions
{
 public static IEnumerable&amp;lt;string&amp;gt; Pair (this IEnumerable&amp;lt;string&amp;gt; source)
 {
  string firstHalf = null;
  foreach (string element in source)
  if (firstHalf == null)
   firstHalf = element;
  else
  {
   yield return firstHalf + ", " + element;
   firstHalf = null;
  }
 }
}
&lt;/string&gt;&lt;/pre&gt;There is other statement besides &lt;i&gt;yeild &lt;/i&gt;return&lt;br /&gt;
&lt;i&gt;&lt;b&gt;yield break&lt;/b&gt;&lt;/i&gt;&lt;br /&gt;
stops returning sequence elements (this happens automatically if control reaches the end of the iterator method body). &lt;br /&gt;
The iterator code uses the yield return statement to return each element in turn. yield break ends the iteration. &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Constraint&lt;/b&gt;&lt;br /&gt;
The &lt;i&gt;yield &lt;/i&gt;statement can only appear inside an iterator block, which might be used as a body of a method, operator, or accessor. The body of such methods, operators, or accessors is controlled by the following restrictions:&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;Unsafe blocks are not allowed.&lt;/li&gt;
&lt;li&gt;Parameters to the method, operator, or accessor cannot be ref or out.&lt;/li&gt;
&lt;li&gt;A yield statement cannot appear in an anonymous method. &lt;/li&gt;
&lt;li&gt;When used with expression, a yield return statement cannot appear in a catch block or in a try block that has one or more catch clauses. &lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/06/c-state-machine-yield.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>4</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-2009203433613608336</guid><pubDate>Fri, 15 Jun 2012 12:24:00 +0000</pubDate><atom:updated>2012-06-15T08:24:08.339-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><title>String concat with null</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;&lt;b&gt;Source :&lt;/b&gt; &lt;a href="http://stackoverflow.com/questions/10814282/why-is-this-valid-c-sharp-code/10814338#10814338"&gt;My Higest Voted answer on StackOverflow&lt;/a&gt;&lt;br /&gt;
&lt;b&gt;Question &lt;/b&gt;This is valid C# code&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var bob = "abc" + null + null + null + "123";  // abc123
&lt;/pre&gt;This is not valid C# code&lt;br /&gt;
&lt;pre class="brush: csharp"&gt;var wtf = null.ToString(); // compiler error
&lt;/pre&gt;Why is the first statement valid?&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Answer&lt;/b&gt;&lt;br /&gt;
&lt;strong&gt;&lt;em&gt;The reason for first one working:&lt;/em&gt;&lt;/strong&gt;&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/ms228504.aspx"&gt;From MSDN&lt;/a&gt;: &lt;br /&gt;
In string concatenation operations,the C# compiler treats a null string the same as an empty string, but it does not convert the value of the original null string.&lt;br /&gt;
&lt;br /&gt;
More information on the &lt;a href="http://msdn.microsoft.com/en-us/library/aa691375(VS.71).aspx"&gt;+ binary operator&lt;/a&gt;:&lt;br /&gt;
&lt;br /&gt;
The binary + operator performs string concatenation when one or both operands are of type string. &lt;br /&gt;
&lt;br /&gt;
If an operand of string concatenation is null, an empty string is substituted. Otherwise, any non-string argument is converted to its string representation by invoking the virtual `ToString` method inherited from type object.&lt;br /&gt;
&lt;br /&gt;
If &lt;i&gt;ToString &lt;/i&gt;returns &lt;i&gt;null&lt;/i&gt;, an empty string is substituted.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;&lt;em&gt;The reason of the error in second is:&lt;/em&gt;&lt;br /&gt;
&lt;i&gt;&lt;/i&gt;&lt;/b&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/edakx9da.aspx"&gt;null (C# Reference)&lt;/a&gt; - The null keyword is a literal that represents a null reference, one that does not refer to any object. null is the default value of reference-type variables. &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/06/string-concat-with-null.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><thr:total>1</thr:total></item><item><guid isPermaLink="false">tag:blogger.com,1999:blog-1194836729866470946.post-3020017159590373300</guid><pubDate>Thu, 14 Jun 2012 19:07:00 +0000</pubDate><atom:updated>2012-06-15T08:17:14.549-04:00</atom:updated><category domain="http://www.blogger.com/atom/ns#">c#</category><title>Concat() vs Union()</title><description>&lt;div dir="ltr" style="text-align: left;" trbidi="on"&gt;Recently I worked with the two method on my enumeration object that are Union() and Concat(). This methods used to mostly used by developer to combine two collection in single collection, but that's not true here in this post I am going to show the actual difference between this two methods.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Def. from MSDN&lt;/b&gt;&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/bb302894.aspx"&gt;Enumerable.Concat&lt;tsource&gt;&amp;nbsp; &lt;/tsource&gt;&lt;/a&gt; - Concatenates two sequences.&lt;br /&gt;
&lt;a href="http://msdn.microsoft.com/en-us/library/bb341731.aspx"&gt;Enumerable.Union&lt;tsource&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/tsource&gt;&lt;/a&gt; - Produces the set union of two sequences by using the default equality comparer.&lt;br /&gt;
&lt;br /&gt;
If you read the def. carefully you actually find difference between two methods. Now to understand it better way have look to below example &lt;br /&gt;
&lt;pre class="brush: csharp"&gt;int[] ints1 = { 1, 2, 3 };
int[] ints2 = { 3, 4, 5 };
IEnumerable&lt;int&gt; union = ints1.Union(ints2);
Console.WriteLine("Union");
foreach (int num in union)
{
   Console.Write("{0} ", num);
}
Console.WriteLine();
IEnumerable&lt;int&gt; concat = ints1.Concat(ints2);
Console.WriteLine("Concat");
foreach (int num in concat)
{
   Console.Write("{0} ", num);
}
&lt;/int&gt;&lt;/int&gt;&lt;/pre&gt;&lt;b&gt;Output &lt;/b&gt;&lt;br /&gt;
&lt;a href="http://1.bp.blogspot.com/-UtZSCj47uTc/T9oyTjcS8HI/AAAAAAAADIE/G7h1wKfJFMI/s1600/output%2B.jpg" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" height="92" src="http://1.bp.blogspot.com/-UtZSCj47uTc/T9oyTjcS8HI/AAAAAAAADIE/G7h1wKfJFMI/s640/output%2B.jpg" width="640" /&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The output shows that &lt;i&gt;&lt;b&gt;Concat()&lt;/b&gt;&lt;/i&gt; method just combine two enumerable collection to single one but doesn't  perform any operation/ process any element just return single enumerable collection with all element of two enumerable collections.&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;&lt;b&gt;Union()&lt;/b&gt;&lt;/i&gt; method return the enumerable collection by eliminating the duplicate i.e just return single element if the same element exists in both enumerable collection on which union is performed.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Important point to Note&lt;/b&gt;&lt;br /&gt;
&lt;ul style="text-align: left;"&gt;&lt;li&gt;By this fact we can say that &lt;i&gt;Concat()&lt;/i&gt; is faster than &lt;i&gt;Union()&lt;/i&gt; because it doesn't do any processing.&amp;nbsp;&lt;/li&gt;
&lt;li&gt;But if after combining two collection using &lt;i&gt;Concat() &lt;/i&gt;having single collection with too many number of duplicate element and if you want to perform further operation on that created collection takes longer time than collection created using &lt;i&gt;Union()&lt;/i&gt; method, because &lt;i&gt;Union()&lt;/i&gt; eliminate duplicate and create collection with less elements.   &lt;/li&gt;
&lt;/ul&gt;&lt;/div&gt;</description><link>http://pranayamr.blogspot.com/2012/06/concat-vs-union.html</link><author>pranayamr@gmail.com (Pranay Rana)</author><media:thumbnail url="http://1.bp.blogspot.com/-UtZSCj47uTc/T9oyTjcS8HI/AAAAAAAADIE/G7h1wKfJFMI/s72-c/output%2B.jpg" height="72" width="72" /><thr:total>0</thr:total></item><language>en-us</language><copyright>Pranay Rana @2010 Gmind Solution</copyright><media:credit role="author">Pranay Rana</media:credit><media:rating>nonadult</media:rating><media:description type="plain">Gmind Solution</media:description></channel></rss>
