<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tech Insight ! &#187; .net 3.5</title>
	<atom:link href="http://techinsight.dhanashree.com/category/net-3-5/feed/" rel="self" type="application/rss+xml" />
	<link>http://techinsight.dhanashree.com</link>
	<description>Technical blog on ASP.Net, PHP, Web Development, Web hosting , Database Programming</description>
	<lastBuildDate>Fri, 12 Aug 2011 07:26:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to convert value to Enum</title>
		<link>http://techinsight.dhanashree.com/how-to-convert-value-to-enum/</link>
		<comments>http://techinsight.dhanashree.com/how-to-convert-value-to-enum/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 11:10:18 +0000</pubDate>
		<dc:creator>jatin</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[C#.net]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/?p=238</guid>
		<description><![CDATA[How to convert a value into Enum?
In project, we sometime come across a kind of situation where we need to convert some value to Enum and an Enum object into certain value.
One solution to this is we can write chunk of switch-case statement and return the desired result.
But is there any rationalize method to achieve [...]]]></description>
			<content:encoded><![CDATA[<h1>How to convert a value into Enum?</h1>
<p>In project, we sometime come across a kind of situation where we need to convert some value to Enum and an Enum object into certain value.</p>
<p>One solution to this is we can write chunk of switch-case statement and return the desired result.</p>
<p>But is there any rationalize method to achieve this? Yes here is the piece of code that you may find it useful. I have implemented it in many of my project and it really helps me reduce some overloaded work for me.</p>
<p>So here is that code for you in which I demonstrate how you can convert a value into Enum object.</p>
<p><span style="font-family: Courier New;"><span style="color: blue;">using</span> System;</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">using</span> System.Collections.Generic;</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">using</span> System.Linq;</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">public</span></span></p>
<p><span style="color: blue;">static</span></p>
<p><span style="color: blue;">class</span></p>
<p><span style="color: #2b91af;">EnumsConverter</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">public</span></p>
<p><span style="color: blue;">static</span> T ConvertValueToEnum&lt;T&gt;(<span style="color: blue;">object</span> value, T defaultValue)</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: #2b91af;">Type</span> enumType = <span style="color: #2b91af;">Reflection</span>.ExtractEnumType(<span style="color: blue;">typeof</span>(T));</p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">if</span> (enumType == <span style="color: blue;">null</span>)</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">throw</span></p>
<p><span style="color: blue;">new</span></p>
<p><span style="color: #2b91af;">ArgumentException</span>(<span style="color: #a31515;">&#8220;Type T is not an enumeration&#8221;</span>, <span style="color: #a31515;">&#8220;T&#8221;</span>);</p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">try</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">return</span> (T)<span style="color: #2b91af;">Enum</span>.Parse(enumType, value.ToString());</p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">catch</span> (<span style="color: #2b91af;">ArgumentException</span>)</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">return</span> defaultValue;</p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">public</span></p>
<p><span style="color: blue;">static</span> T ConvertValueToEnum&lt;T&gt;(<span style="color: blue;">object</span> value)</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: #2b91af;">Type</span> enumType = <span style="color: #2b91af;">Reflection</span>.ExtractEnumType(<span style="color: blue;">typeof</span>(T));</p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">if</span> (enumType == <span style="color: blue;">null</span>)</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">throw</span></p>
<p><span style="color: blue;">new</span></p>
<p><span style="color: #2b91af;">ArgumentException</span>(<span style="color: #a31515;">&#8220;Type T is not an enumeration&#8221;</span>, <span style="color: #a31515;">&#8220;T&#8221;</span>);</p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">return</span> (T)<span style="color: #2b91af;">Enum</span>.Parse(enumType, value.ToString());</p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p>Here there are two overloaded methods. All you have to do is pass your desired enumeration object. The method itself will identify and return attached valued to that particular Enum object.</p>
<p>Happy programming…</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><br />
<span style="font-family: Calibri;">NOTE<span style="mso-spacerun: yes;"> </span>: Also visit <a href="http://www.dhanashree.com">www.dhanashree.com</a></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><br />
<a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/how-to-convert-value-to-enum/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to call Google MAP Webservice API from asp.net, call Geocoding Map API Webservice from asp.net</title>
		<link>http://techinsight.dhanashree.com/how-to-call-google-map-webservice-api-from-asp-net-call-geocoding-map-api-webservice-from-asp-net/</link>
		<comments>http://techinsight.dhanashree.com/how-to-call-google-map-webservice-api-from-asp-net-call-geocoding-map-api-webservice-from-asp-net/#comments</comments>
		<pubDate>Thu, 07 Oct 2010 11:04:49 +0000</pubDate>
		<dc:creator>jatin</dc:creator>
				<category><![CDATA[.Net 2.0]]></category>
		<category><![CDATA[.net 3.5]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/?p=234</guid>
		<description><![CDATA[How the necessities arise?
 
Necessity is mother of invention.
I was assigned a task to develop a restaurant portal.
The basic aim behind creation of this project is to have a marketplace for all restaurant owner or hotel business, and provide end user with integrative google map services so that they visualize realtime.
If we are supposed to [...]]]></description>
			<content:encoded><![CDATA[<p><strong>How the necessities arise?</strong></p>
<p><strong> </strong></p>
<p>Necessity is mother of invention.</p>
<p>I was assigned a task to develop a restaurant portal.</p>
<p>The basic aim behind creation of this project is to have a marketplace for all restaurant owner or hotel business, and provide end user with integrative google map services so that they visualize realtime.</p>
<p>If we are supposed to insert a simple google map, then we just have to insert a piece javascript code, and boom you are done.</p>
<p>But in my project, I have requirement where different restaurant/hotel owner register and give us their details and addresses.</p>
<p><strong>So, What is Google Map API?</strong></p>
<p><strong> </strong></p>
<p>The Google Maps API lets you embed Google Maps in your own web pages with JavaScript. The API provides a number of utilities for manipulating maps and adding content to the map through a variety of services, allowing you to create robust maps applications on your website.</p>
<p>All map related functionalities can be achieved as seen on <a href="http://maps.google.com/">http://maps.google.com/</a></p>
<p><strong>Then what was hurdle for me in using Map API?</strong></p>
<p><strong> </strong></p>
<p>These are the pure JavaScript code..!! You can develop whatever rich Map application you wanted to develop by writing piece of JavaScript codes.</p>
<p>Actually to host a map on your page, you need to have two parameters, Latitude &amp; Longitude. But how do I get lat. and long. from server side scripting?</p>
<p>But I had no idea how to call Google Map API from C#/VB.NET.</p>
<p>So for my project, as usual, I start googling to find out my piece of sweet.</p>
<p>After searching for couple of hours, I come across this good article.</p>
<p><a href="http://webcodeblog.com/2010/04/24/obtain-latitude-and-longitude-co-ordinates-for-an-address-using-asp-net-and-the-google-maps-api/">http://webcodeblog.com/2010/04/24/obtain-latitude-and-longitude-co-ordinates-for-an-address-using-asp-net-and-the-google-maps-api/</a></p>
<p>Here the author explained the how to obtain the latitude and longitude co-ordinates for an address using the Google Maps API.</p>
<p>But again here, it is pure JavaScript that utilize Google Map API to get lat &amp; long of any address. But my problem is still there?</p>
<p><strong>Hurrray….. I found the solution</strong></p>
<p><strong> </strong></p>
<p>Then accidently I come to across Google Maps API Web Services.</p>
<p>It is basically Maps API Web Services, a collection of HTTP interfaces to Google services providing geographic data for your maps applications.</p>
<p>In the documentation (<a href="http://code.google.com/apis/maps/documentation/webservices/">http://code.google.com/apis/maps/documentation/webservices/</a>),</p>
<p>I see that you can utilize Google Map API web service by making HTTP request to a specific URL, providing necessary parameters with URL. Which in return, gives a response in desired format.</p>
<p>You can get response inform of JSON or XML.</p>
<p>Say for e.g. it can be called like this URL</p>
<p><a href="http://maps.google.com/maps/geo?q=khandala, maharashtra&amp;output=xml&amp;key=xxxxxxxxxxxxxx"><span style="font-family: Courier New;">http://maps.google.com/maps/geo?q=khandala, maharashtra&amp;output=xml&amp;key=xxxxxxxxxxxxxx</span></a><span style="color: green; font-family: Courier New;"> </span></p>
<p>Paste it into your browser and you will receive a XML response.</p>
<p>Immediately, I get one &#8220;Mantos (<em>Dimag ki batti jala de</em>)&#8221; and found a clue <span style="font-family: Wingdings;">J</span></p>
<p>I thought why not to develop a library that make a call to this URL and parse the returned output to get lat &amp; long…!!?</p>
<p>So for that purpose I write this library.</p>
<p>Obviously, before doing all these, you will need to register with Google Map API and get a key so that you can utilize their API.</p>
<p>Sign up and get a Google Maps API Key.  You will need one for the domain name of where you will be hosting the map.  You can get your API Key from here (<a title="http://code.google.com/apis/maps/signup.html" href="http://code.google.com/apis/maps/signup.html">http://code.google.com/apis/maps/signup.html</a>)</p>
<p>Following is the complete code that I used to call Google Map <a href="http://code.google.com/apis/maps/documentation/geocoding/">Geocoding API</a> from Asp.net.</p>
<p>All you have to do Is to just create a class file and paste the following code. And you are ready to call Google Map <a href="http://code.google.com/apis/maps/documentation/geocoding/">Geocoding API</a>.</p>
<p><strong>How to call Geocoding API from Asp.net?</strong></p>
<p><strong> </strong></p>
<p><strong>Step 1</strong></p>
<p><strong> </strong></p>
<p><span style="font-family: Courier New;"> <span style="color: gray;">///</span><span style="color: green;"> Resolve addresses into latitude/longitude coordinates using Google MAP API webservices</span></span></p>
<p><span style="font-family: Courier New;"> <span style="color: gray;"> </span><span style="color: blue;">public static</span><span style="color: blue;"> class</span><span style="color: #2b91af;"> Geocoder</span></span></p>
<p><span style="font-family: Courier New;">{</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">private</span><span style="color: blue;"> static</span><span style="color: blue;"> string</span> _GoogleMapsKey = <span style="color: #2b91af;">Config</span>.getAppSetting(<span style="color: #a31515;">&#8220;GoogleMapsKey&#8221;</span>);</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">public</span><span style="color: blue;"> static</span><span style="color: #2b91af;"> Geolocation</span>? ResolveAddress(<span style="color: blue;">string</span> query)</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">if</span> (<span style="color: blue;">string</span>.IsNullOrEmpty(_GoogleMapsKey))</span></p>
<p><span style="font-family: Courier New;"> _GoogleMapsKey = <span style="color: #2b91af;">ConfigurationManager</span>.AppSettings[<span style="color: #a31515;">"GoogleMapsKey"</span>];</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">string</span> url = <span style="color: #a31515;">&#8220;http://maps.google.com/maps/geo?q={0}&amp;output=xml&amp;key=&#8221;</span> + _GoogleMapsKey; <span style="color: green;"> </span></p>
<p><span style="font-family: Courier New;"> url = <span style="color: #2b91af;">String</span>.Format(url, query);</span></p>
<p><span style="font-family: Courier New;"><span style="color: #2b91af;">XmlNode</span> coords = <span style="color: blue;">null</span>;</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">try</span>{</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">string</span> xmlString = GetUrl(url);</span></p>
<p><span style="font-family: Courier New;"><span style="color: #2b91af;">XmlDocument</span> xd = <span style="color: blue;">new</span><span style="color: #2b91af;"> XmlDocument</span>();</span></p>
<p><span style="font-family: Courier New;"> xd.LoadXml(xmlString);</span></p>
<p><span style="font-family: Courier New;"><span style="color: #2b91af;">XmlNamespaceManager</span> xnm = <span style="color: blue;">new</span><span style="color: #2b91af;"> XmlNamespaceManager</span>(xd.NameTable);</span></p>
<p><span style="font-family: Courier New;"> coords = xd.GetElementsByTagName(<span style="color: #a31515;">&#8220;coordinates&#8221;</span>)[0];</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">catch</span> { }</p>
<p><span style="font-family: Courier New;"><span style="color: #2b91af;">Geolocation</span>? gl = <span style="color: blue;">null</span>;</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">if</span> (coords != <span style="color: blue;">null</span>)</span><span style="font-family: Courier New;">{</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">string</span>[] coordinateArray = coords.InnerText.Split(<span style="color: #a31515;">&#8216;,&#8217;</span>);</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">if</span> (coordinateArray.Length &gt;= 2)</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> gl = <span style="color: blue;">new</span><span style="color: #2b91af;"> Geolocation</span>(<span style="color: #2b91af;">Convert</span>.ToDecimal(coordinateArray[1].ToString()), <span style="color: #2b91af;">Convert</span>.ToDecimal(coordinateArray[0].ToString()));</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">return</span> gl;</p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> <span style="color: gray;"> </span></span></p>
<p><span style="color: blue;">public</span><span style="color: blue;"> static</span><span style="color: #2b91af;"> Geolocation</span>? ResolveAddress(<span style="color: blue;">string</span> address, <span style="color: blue;">string</span> city, <span style="color: blue;">string</span> state, <span style="color: blue;">string</span> postcode, <span style="color: blue;">string</span> country)</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">return</span> ResolveAddress(address + <span style="color: #a31515;">&#8220;,&#8221;</span> + city + <span style="color: #a31515;">&#8220;,&#8221;</span> + state + <span style="color: #a31515;">&#8220;,&#8221;</span> + postcode + <span style="color: #a31515;">&#8221; &#8220;</span> + country);</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">private</span><span style="color: blue;"> static</span><span style="color: blue;"> string</span> GetUrl(<span style="color: blue;">string</span> url)</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">string</span> result = <span style="color: blue;">string</span>.Empty;</span></p>
<p><span style="font-family: Courier New;"> System.Net.<span style="color: #2b91af;">WebClient</span> Client = <span style="color: blue;">new</span><span style="color: #2b91af;"> WebClient</span>();</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">using</span> (<span style="color: #2b91af;">Stream</span> strm = Client.OpenRead(url))</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"><span style="color: #2b91af;">StreamReader</span> sr = <span style="color: blue;">new</span><span style="color: #2b91af;"> StreamReader</span>(strm);</span></p>
<p><span style="font-family: Courier New;"> result = sr.ReadToEnd();</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">return</span> result;</p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">public</span><span style="color: blue;"> struct</span><span style="color: #2b91af;"> Geolocation</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">public</span><span style="color: blue;"> decimal</span> Lat;</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">public</span><span style="color: blue;"> decimal</span> Lon;</p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">public</span> Geolocation(<span style="color: blue;">decimal</span> lat, <span style="color: blue;">decimal</span> lon)</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"> Lat = lat;</span></p>
<p><span style="font-family: Courier New;"> Lon = lon;</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> </span></p>
<p><span style="color: blue;">public</span><span style="color: blue;"> override</span><span style="color: blue;"> string</span> ToString()</p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">return</span><span style="color: #a31515;"> &#8220;Latitude: &#8220;</span> + Lat.ToString() + <span style="color: #a31515;">&#8221; Longitude: &#8220;</span> + Lon.ToString();</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">public</span><span style="color: blue;"> string</span> ToQueryString()</span></p>
<p><span style="font-family: Courier New;"> {</span></p>
<p><span style="font-family: Courier New;"><span style="color: blue;">return</span><span style="color: #a31515;"> &#8220;+to:&#8221;</span> + Lat + <span style="color: #a31515;">&#8220;%2B&#8221;</span> + Lon;</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><span style="font-family: Courier New;"> }</span></p>
<p><strong>Step 2</strong></p>
<p><strong> </strong></p>
<p>Now, you just need to put a key in AppSetting section that hold your Google Map API key.</p>
<p><strong>Step 3</strong></p>
<p><strong> </strong></p>
<p>I have provided 2 overloaded methods to call Geocoding Map API Webservice, named <span style="font-family: Courier New;">ResolveAddress.</span></p>
<p>Say for e.g. you can call method like this.</p>
<p><span style="font-family: Courier New;"><span style="color: #2b91af;">Geocoder.</span>ResolveAddress(&#8220;University road&#8221;,&#8221;rajkot&#8221;,&#8221;gujarat&#8221;,&#8221;",&#8221;India&#8221;)</span></p>
<p>I hope this will solve your purpose, those who wanted to develop Geocoding application, those who want to access Google Map Webservice API from c#/vb.net.</p>
<p>Happy programming…</p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span style="color: red;" lang="EN-IN"><span style="font-size: 11pt;"><br />
<span style="font-family: Calibri;">NOTE<span style="mso-spacerun: yes;"> </span>: Also visit <a href="http://www.dhanashree.com">www.dhanashree.com</a></span></span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><br />
<a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;"><br />
Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/how-to-call-google-map-webservice-api-from-asp-net-call-geocoding-map-api-webservice-from-asp-net/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Understanding asp.net MVC (Model View Controller) architecture</title>
		<link>http://techinsight.dhanashree.com/understanding-asp-net-mvc-model-view-controller-architecture/</link>
		<comments>http://techinsight.dhanashree.com/understanding-asp-net-mvc-model-view-controller-architecture/#comments</comments>
		<pubDate>Fri, 05 Feb 2010 06:21:38 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[.net framework]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Web Developement]]></category>
		<category><![CDATA[.net developement]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/understanding-asp-net-mvc-model-view-controller-architecture/</guid>
		<description><![CDATA[This article is intended to provide basic concept and fundamentals of asp.net MVC (Model View Controller) architecture workflow for beginners.
Introduction:

&#8220;M&#8221;  &#8220;V&#8221;   &#8220;C&#8221;  stands for &#8220;MODEL&#8221;  &#8220;VIEW&#8221; &#8220;CONTROLLER&#8221; , asp.net MVC is an architecture to develop asp.net web applications in a different manner than the traditional asp.net web development , web [...]]]></description>
			<content:encoded><![CDATA[<p>This article is intended to provide basic concept and fundamentals of asp.net MVC (Model View Controller) architecture workflow for beginners.</p>
<p><span style="text-decoration: underline;">Introduction:<br />
</span></p>
<p>&#8220;M&#8221;  &#8220;V&#8221;   &#8220;C&#8221;  stands for &#8220;MODEL&#8221;  &#8220;VIEW&#8221; &#8220;CONTROLLER&#8221; , asp.net MVC is an architecture to develop asp.net web applications in a different manner than the traditional asp.net web development , web applications developed with asp.net MVC is even more SEO (Search Engine Friendly ) friendly.</p>
<p>Developing asp.net MVC application requires Microsoft .net framework 3.5 or higher.</p>
<p><span style="text-decoration: underline;">MVC interaction with browser:<br />
</span></p>
<p>Like a normal web server interaction, MVC application also accept request and respond web browser same way.</p>
<p><img src="http://techinsight.dhanashree.com/article-images/020510_0621_Understandi1.png" alt="" /></p>
<p><span style="text-decoration: underline;">Inside MVC architecture:<br />
</span></p>
<p>Whole asp.net MVC architecture is based on Microsoft .net framework 3.5 and in addition uses LINQ to SQL Server.</p>
<p><strong>What is a Model? </strong></p>
<ol>
<li>MVC <strong>model</strong> is basically a C# or VB.net class</li>
<li>A <strong>model</strong> is accessible by both <strong>controller</strong> and <strong>view</strong></li>
<li>A <strong>model</strong> can be used to pass data from <strong>Controller</strong> to <strong>view</strong>.</li>
<li>A <strong>view</strong> can use model to display data in page.</li>
</ol>
<p><strong>What is a View?<br />
</strong></p>
<ol>
<li>View is an ASPX page without having a code behind file</li>
<li>All page specific HTML generation and formatting can be done inside view</li>
<li>One can use Inline code (server tags ) to develop dynamic pages</li>
<li>A request to <strong>view</strong> (ASPX page) can be made only from a controller&#8217;s action method</li>
</ol>
<p><strong>What is a Controller?<br />
</strong></p>
<ol>
<li><strong>Controller</strong> is basically a C# or VB.net class which inherits <strong>system.mvc.controller</strong></li>
<li><strong>Controller</strong> is a heart of whole MVC architecture</li>
<li>Inside<strong> Controller&#8217;s class </strong>action methods can be implemented which is responsible for responding to browser OR calling view&#8217;s.<strong><br />
</strong></li>
<li><strong>Controller</strong> can access and use <strong>model</strong> class to pass data to <strong>view&#8217;s<br />
</strong></li>
<li><strong>Controller </strong>uses <strong>ViewData </strong>to pass any data to <strong>view</strong></li>
</ol>
<p><img src="http://techinsight.dhanashree.com/article-images/020510_0621_Understandi2.png" alt="" /></p>
<h3><span style="text-decoration: underline;"><span style="font-weight: normal;">MVC file structure &amp; file naming standards</span><br />
</span></h3>
<p>MVC uses a standard directory structure and file naming standards which is very important part of MVC application development.</p>
<p>Inside the ROOT directory of the application there must be 3 directories each for model, view and Controller.</p>
<p>Apart from 3 directories there must have a <strong>Global.asax </strong>file in root folder. And a web.config like a traditional asp.net application.</p>
<ul>
<li>
<div><strong>Root </strong>[directory]<strong><br />
</strong></div>
<ul>
<li>
<div><strong>Controller</strong> [directory]</div>
<ul>
<li>Controller CS files</li>
</ul>
</li>
<li>
<div><strong>Models</strong> [directory]</div>
<ul>
<li>Model CS files</li>
</ul>
</li>
<li>
<div><strong>Views </strong>[directory]<strong><br />
</strong></div>
<ul>
<li>View CS files<strong><br />
</strong></li>
</ul>
</li>
<li>Global.asax</li>
<li>Web.config</li>
</ul>
</li>
</ul>
<p><span style="text-decoration: underline;">Asp.net MVC Execution life cycle<br />
</span></p>
<p>Here is how MVC architecture executes the requests to browser and objects interactions with each other.</p>
<p>A step by step process is explained below:  <strong>[Refer figure as given below]</strong></p>
<p><img src="http://techinsight.dhanashree.com/article-images/020510_0621_Understandi3.png" alt="" /></p>
<p><span style="color: #0070c0;"><strong>Step 1: </strong><br />
<strong>Browser request</strong><br />
</span></p>
<p>Browser request happens with a specific URL. Let&#8217;s assume that user entering URL like: [xyz.com]/home/index/</p>
<p><span style="color: #0070c0;"><strong>Step 2:  Job of Global.asax &#8211; MVC routing<br />
</strong></span></p>
<p>The specified URL will first get parsed via application_start() method inside Global.asax file. From the requested URL it will parse the <strong>Controller, Action and ID.<br />
</strong></p>
<p>So for [xyz.com]/home/index/:</p>
<p>Controller = home</p>
<p>Action = index()</p>
<p>ID = empty  &#8212; we have not specified ID in [xyz.com]/home/index/, so it will consider as empty string</p>
<p><span style="color: #0070c0;"><strong>Step 3:  Controller and Action methods<br />
</strong></span></p>
<p>MVC now find the <strong>home controller</strong> class in controller directory.  A controller class contains different action methods,</p>
<p>There can be more than one action method, but MVC will only invokes the action method which is been parsed from the URL, its index() in our case.</p>
<p>So something like: <strong>homeController.index() </strong>will happen inside MVC controller class.</p>
<p>Invoking action method can return plain text string OR rendered HTML by using view.</p>
<p><span style="color: #0070c0;"><strong>Step 4:  Call to View (ASPX page)<br />
</strong></span></p>
<p>Invoking view will return <strong>view()</strong> . a call to view will access the particular ASPX page inside the view directory and generate the rendered HTML from the ASPX and will respond back to the browser.</p>
<p>In our case controller was <strong>home </strong>and action was <strong>index().</strong> So calling view() will return a rendered HTML from the ASPX page located at <strong>/views/home/index.aspx.<br />
</strong></p>
<p><strong>This is it, the whole process ends here. So this is how MVC architecture works.</strong></p>
<p><span style="font-family: Calibri; font-size: 15px; color: #ff0000;">NOTE<span style="mso-spacerun: yes;"> </span>:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/understanding-asp-net-mvc-model-view-controller-architecture/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Dot Net framework 3.5, C#, VB.Net Language Improvements: Automatic Properties, Object initializers, Collection Initializers, Lambda expression, Anonymous type</title>
		<link>http://techinsight.dhanashree.com/dot-net-framework-3-5-c-vb-net-language-improvements-automatic-properties-object-initializers-collection-initializers-lambda-expression-anonymous-type/</link>
		<comments>http://techinsight.dhanashree.com/dot-net-framework-3-5-c-vb-net-language-improvements-automatic-properties-object-initializers-collection-initializers-lambda-expression-anonymous-type/#comments</comments>
		<pubDate>Tue, 02 Feb 2010 11:15:52 +0000</pubDate>
		<dc:creator>kiran</dc:creator>
				<category><![CDATA[.net 3.5]]></category>
		<category><![CDATA[.net framework]]></category>
		<category><![CDATA[Tools & Technology]]></category>
		<category><![CDATA[.net developement]]></category>

		<guid isPermaLink="false">http://techinsight.dhanashree.com/?p=167</guid>
		<description><![CDATA[The new .net 3.5 has significant improved features. This feature makes the .net programming concept more sophisticated. You will now be able to write less code and build more dynamic application using those.
From all of them what the most I like is the LINQ, which allow you to query over variety of objects.
LINQ is all [...]]]></description>
			<content:encoded><![CDATA[<p>The new .net 3.5 has significant improved features. This feature makes the .net programming concept more sophisticated. You will now be able to write less code and build more dynamic application using those.</p>
<p>From all of them what the most I like is the LINQ, which allow you to query over variety of objects.</p>
<p>LINQ is all about queries, they returns a set of matching objects, a single object, or a subset of fields from an object or set of objects. In LINQ, this returned set of objects is called a <em>sequence</em>.</p>
<p>Basically LINQ comes in variety of flavors’ like following:</p>
<ul>
<li>LINQ to Objects</li>
<li>LINQ to XML</li>
<li>LINQ to Dataset</li>
<li>LINQ to SQL</li>
<li>LINQ to Entities</li>
</ul>
<p>Well there is a detailed discussion on LINQ further in this article. Let me first make you guys introduce to the language improvements in .net 3.5. In fact I believe that these new improvements are essential to learn before we actually get dig into the LINQ J.</p>
<p>To summarize quickly, here are the list of new language feature that are shipped with .Net 3.5.</p>
<ul>
<li>Automatic properties</li>
<li>Object initializers, Collection initializers</li>
<li>Anonymous types</li>
<li>Extension methods</li>
<li>Query Expression</li>
</ul>
<p>Well if you are the C# developer, I believe you will really love to have such significant improvement. Because these features puts extra wing on your programming skill.</p>
<p>The important is not that you learn the latest technology of .Net 3.5 like WCF, WPF, Silverlight etc. These are the core part of basic programming. Its like you should be knowing the if syntax of C programming language before you actually write your first “Hello word” program J</p>
<p>So let’s go through each of them step by step and try to understand what they are and how it can help the developer to create rich internet/desktop application.</p>
<ul>
<li><strong>Automatic Property</strong></li>
</ul>
<p>Before I explain you the concept of “automatic property in .net 3.5, can you guys first please try to go through the following code?</p>
<p>public class MShoppingCart</p>
<p>{</p>
<p>private int _cartId;</p>
<p>public int CartId</p>
<p>{</p>
<p>get { return _cartId; }</p>
<p>set { _cartId = value; }</p>
<p>}</p>
<p>private int _customerid;</p>
<p>public int Customerid</p>
<p>{</p>
<p>get { return _customerid; }</p>
<p>set { _customerid = value; }</p>
<p>}</p>
<p>private int _billingaddressid;</p>
<p>public int Billingaddressid</p>
<p>{</p>
<p>get { return _billingaddressid; }</p>
<p>set { _billingaddressid = value; }</p>
<p>}</p>
<p>private int _shippingaddressid;</p>
<p>public int Shippingaddressid</p>
<p>{</p>
<p>get { return _shippingaddressid; }</p>
<p>set { _shippingaddressid = value; }</p>
<p>}</p>
<p>private MShippingCartItem _cartitem;</p>
<p>public MShippingCartItem Cartitem</p>
<p>{</p>
<p>get { return _cartitem; }</p>
<p>set { _cartitem = value; }</p>
<p>}</p>
<p>}</p>
<p>Most of the time we are used to write such model classes. This are the most basic and popular mechanism in returning a wrapper classes. The basic purpose of writing such getter/setter property is to hide the actual private member of our classes. It has been the standard pattern to access the private method of any classes. Well you may arise with a question that why do we actually need to write such getter/setter properties. Can’t we simply expose the private member? Well the answer is YES, but I would request you to remember the fundamental of object oriented programming. J</p>
<p>Anyway there are basically two reason of not doing so. Following are this:</p>
<ol>
<li>You won’t be easily able to bind those private variable to controls</li>
<li>You will not be able to modify them into property later on.</li>
</ol>
<p>The first point is quite understandable, what do you mean by the second one? Well, say for e.g. if you need to add any business logic or validation logic when assigning value to any private variable then? You will not be able to do that.</p>
<p>So what if we need not to write even the private variables? Exited, yes the new version of .Net 3.5 allows you have such facility. The concept is called automatic property. All you have to do is to write the getter/setter property. You need not to worry about the private member of that property. The compiler will decide and prepare base private member for you on the fly.</p>
<p>See the example in the following.</p>
<p>public class MShoppingCart</p>
<p>{</p>
<p>public int CartId</p>
<p>{</p>
<p>get;</p>
<p>set;</p>
<p>}</p>
<p>public int Customerid</p>
<p>{</p>
<p>get;</p>
<p>set;</p>
<p>}</p>
<p>public int Billingaddressid</p>
<p>{</p>
<p>get;</p>
<p>set;</p>
<p>}</p>
<p>public int Shippingaddressid</p>
<p>{</p>
<p>get;</p>
<p>set;</p>
<p>}</p>
<p>private MShippingCartItem _cartitem;</p>
<p>public MShippingCartItem Cartitem</p>
<p>{</p>
<p>get;</p>
<p>set;</p>
<p>}</p>
<p>}</p>
<p>Now it this case when the compiler will encounter this properties while compiling your code, it will automatically expose the private variable for each of property with its associated type. For e.g. compiler automatically assume and expose the <em>_cartid</em> private variable of integer type. Using advantage of this is we need not to worry about the underlying private variable. In future we can add any sort of validation logic in this property.</p>
<ul>
<li><strong>Object initialization, collection initialization</strong></li>
</ul>
<p>I would like to explain this concept by taking the example of automatic property so that I maintain the continuity for you to understand. Say for e.g. when we want to use the “shopping cart” class that we created earlier. What we do is write following code.</p>
<p>MShoppingCart cart = new MShoppingCart();</p>
<p>cart.CartId = 1;</p>
<p>cart.Customerid = 1001111;</p>
<p>cart.Shippingaddressid = 2333;</p>
<p>cart.Billingaddressid = 2232;</p>
<p>With the feature supported by the .net framework 3.5, you can take advantage of what is called “syntactic sugar”, and that is object initializers.</p>
<p>Using object initializers, you can write the same code given above, in following way.</p>
<p>MShoppingCart cart = new MShoppingCart {CartId =1, Customerid=1001111, Billingaddressid=2232, Shippingaddressid =23333  };</p>
<p>So it allows you to pass the value of all property at the time of initializing the object.</p>
<p>In fact it not only allow to initialize object’s property in this way, you can also have nested initialization of object within any object.</p>
<p>To demonstrate you, see the following example.</p>
<p>MShoppingCart cart = new MShoppingCart { CartId = 1, Customerid = 1001111, Billingaddressid = 2232, Shippingaddressid = 23333, <strong><span style="text-decoration: underline;">Cartitem = new MShippingCartItem { }</span></strong> };</p>
<p>If you see in the highlighted (underlined) part of above code, you can clearly see that the child object can also be initialized in the same way.</p>
<p>As if the new object initialization enhancements were not enough, someone at Microsoft must have said, “What about collections?” Collection initialization allows you to specify the initialization values for a collection, just like you would do for an object, as long as the collection implements the</p>
<p>System.Collections.Generic.ICollection&lt;T&gt; interface.</p>
<p>List&lt;string&gt; presidents = new List&lt;string&gt; { &#8220;Name 1&#8243;, &#8220;Name 2&#8243;, &#8220;Name 3&#8243; };</p>
<p>foreach (string president in presidents)</p>
<p>{</p>
<p>Console.WriteLine(president);</p>
<p>}</p>
<ul>
<li><strong>Anonymous types</strong></li>
</ul>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>What is anonymous type?</p>
<p>Well, we have been familiar till date with different types. They are either custom classes or any of .net’s build in type. So what is actually the anonymous type is. The answer is that the “Anonymous type” has no type defined to it. It has no type name. Though there should be at least one type name associated in .Net. In anonymous type, the type name is specified by the developer doing the programming. It is the compiler which will identify the type to associate with the declaration of any anonymous type.</p>
<p>There is also another significant different in anonymous type is that it is called <em>immutable</em>. The definition of immutable type is that the one that is declared and initialized once. It can’t be altered later on. So anonymous type has the same characteristic. Once you declared and initialized, you can’t alter the anonymous type afterward.</p>
<p>This is also why anonymous types have been introduced. They allow us to create a type on the fly and therefore return only certain values of a given named type. This is very handy when only a subset of properties is needed, properties are joined together or even objects are joined together.</p>
<p>class Program</p>
<p>{</p>
<p>static void Main(string[] args)</p>
<p>{</p>
<p>// create a list of carts with dummy data.</p>
<p>List&lt;MShoppingCart&gt; carts = new List&lt;MShoppingCart&gt;();</p>
<p>carts.Add(new MShoppingCart { CartId=101, Customerid=1001, Billingaddressid=20, Shippingaddressid =30});</p>
<p>carts.Add(new MShoppingCart { CartId = 102, Customerid = 1002, Billingaddressid = 22, Shippingaddressid = 33 });</p>
<p>carts.Add(new MShoppingCart { CartId=103, Customerid=1003, Billingaddressid=23, Shippingaddressid =34});</p>
<p>// query the cart collection to collect cart with id of 101</p>
<p>var result = from c in carts</p>
<p>where c.CartId &gt;= 101</p>
<p>// put the result in a anonymous type</p>
<p>select new { c.Billingaddressid  };</p>
<p>// loop over the result.</p>
<p>foreach (var item in result)</p>
<p>{</p>
<p>// print out the name of the item.</p>
<p>Console.WriteLine(item.Billingaddressid );</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>Anonymous type are mostly used when working with the LINQ. It is utilized highly while querying to your data in LINQ. It is irrespective which flavor of LINQ you are using.</p>
<p>Although the anonymous type can be used in your own code also. It is especially useful when we want to combine different variables into one.</p>
<p>Se for e.g. following example:</p>
<p>// create an anonymous type instance with a name.</p>
<p>var anonymousType = new</p>
<p>{</p>
<p>Name = name,</p>
<p>Age = age,</p>
<p>Nationality = nationality</p>
<p>};</p>
<p>// print the name to the console.</p>
<p>Console.WriteLine(anonymousType.Name);</p>
<p>Though the real time use of anonymous type Is when you use it with the LINQ. I need to write a separate article to demonstrate you actual usage LINQ. J</p>
<ul>
<li><strong>Extension methods</strong></li>
</ul>
<p><strong> </strong></p>
<p>An extension method is a static method of a static class that you can call as though it were an instance method of a different class.</p>
<p>To make you understand the extension method, let me first re cape the class level methods (static methods) and instance methods. The primary different between these two is that the instance method can also be access by initializing object of any class. It can’t be invoked by using class name only. The exact opposite of that is class method. You can only call static class method using the name of class only. You can’t access them using the instance of same class.</p>
<p>I am not gonna give you any example for the above explanation as I expect from you guys that you are familiar with the different I explained.</p>
<p>Extension method is a way of extending existing classes for whatever additional functionality. Let me demonstrate you that by example.</p>
<p>namespace ExtensionMethods</p>
<p>{</p>
<p>public static class StringExtensionMethods</p>
<p>{</p>
<p>public static bool IsNumeric(this string str)</p>
<p>{</p>
<p>try</p>
<p>{</p>
<p>int i = int.Parse(str);</p>
<p>return true;</p>
<p>}</p>
<p>catch</p>
<p>{</p>
<p>}</p>
<p>return false;</p>
<p>}</p>
<p>}</p>
<p>}</p>
<p>In the above given example, almost everything seems to be similar what we are used to in normal programming. But, the difference is clearly seen. You should be able to notice that in the “IsNumeric” static method parameter are passed using <em>this </em>keyword. This keyword tells the compiler what you are going to extend for particular given type. So in this example it tells you that it extends the existing string class.</p>
<p>See for e.g. how to use the extension method.</p>
<p>string s = &#8220;someValue&#8221;;</p>
<p>bool bs = s.IsNumeric();</p>
<p>// bs is false;</p>
<p>string i = &#8220;7&#8243;;</p>
<p>bool bi = i.IsNumeric();</p>
<p>// bi is true;</p>
<ul>
<li><strong>Query Expression</strong></li>
</ul>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p><strong> </strong></p>
<p>One of the conveniences that the C# language provides is the foreach statement. When you use foreach, the compiler translates it into a loop with calls to and MoveNext. The simplicity the foreach statement provides for enumerating through arrays and collections has made it very popular and often used.</p>
<p>One of the features of LINQ that seems to attract developers is the SQL-like syntax available for LINQ queries. The first few LINQ examples in the first chapter of this book use this syntax. This syntax is provided via the new C# 3.0 language enhancement known as query expressions. Query expressions allow LINQ queries to be expressed in nearly SQL form. To perform a LINQ query, it is not required to use query expressions. The alternative is to use standard C# dot notation, calling methods on objects and classes.</p>
<p>Although it is occupy a dedicated book for detail understanding of query expression with LINQ. Just to summarize you, here is the example that shows you what actually query expression does.</p>
<p>For e.g.</p>
<p>string[] names = {</p>
<p>&#8220;Adams&#8221;, &#8220;Arthur&#8221;, &#8220;Buchanan&#8221;, &#8220;Bush&#8221;, &#8220;Carter&#8221;, &#8220;Cleveland&#8221;,</p>
<p>&#8220;Clinton&#8221;, &#8220;Coolidge&#8221;, &#8220;Eisenhower&#8221;, &#8220;Fillmore&#8221;, &#8220;Ford&#8221;, &#8220;Garfield&#8221;,</p>
<p>&#8220;Grant&#8221;, &#8220;Harding&#8221;, &#8220;Harrison&#8221;, &#8220;Hayes&#8221;, &#8220;Hoover&#8221;, &#8220;Jackson&#8221;,</p>
<p>&#8220;Jefferson&#8221;, &#8220;Johnson&#8221;, &#8220;Kennedy&#8221;, &#8220;Lincoln&#8221;, &#8220;Madison&#8221;, &#8220;McKinley&#8221;,</p>
<p>&#8220;Monroe&#8221;, &#8220;Nixon&#8221;, &#8220;Pierce&#8221;, &#8220;Polk&#8221;, &#8220;Reagan&#8221;, &#8220;Roosevelt&#8221;, &#8220;Taft&#8221;,</p>
<p>&#8220;Taylor&#8221;, &#8220;Truman&#8221;, &#8220;Tyler&#8221;, &#8220;Van Buren&#8221;, &#8220;Washington&#8221;, &#8220;Wilson&#8221;};</p>
<p>IEnumerable&lt;string&gt; sequence = from n in names</p>
<p>where n.Length &lt; 6</p>
<p>select n;</p>
<p>foreach (string name in sequence)</p>
<p>{</p>
<p>Console.WriteLine(&#8220;{0}&#8221;, name);</p>
<p>}</p>
<p>Though query expression can be used by two different way. 1) is using dot notation and 2) is using expression syntax.</p>
<p>Hope I could make you understand what are the new improvements in the newer version of .net 3.5.</p>
<p>Once you are aware and familiar with this feature, you are ready to get dig into dip into the word of .net 3.5 for all new existing experience in developing rich internet/enterprise application.</p>
<p>Best luck</p>
<p><span style="font-family: Calibri; font-size: 15px; color: #ff0000;">NOTE<span style="mso-spacerun: yes;"> </span>:</span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">If you are in need of any </span><a href="http://dhanashree.com/web-development-services/asp-php-web-development" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">Web Development</span></a><span style="font-size: 11pt; font-family: Calibri;"> feel free to <span style="text-decoration: underline;"><a href="http://dhanashree.com/contact-web-designing-company" target="_blank">Inquire us</a></span> .<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a></span>. Expertise in <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/dot-net-web-designing" target="_blank">Asp.net Development</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/asp-php-web-development/lamp-development-php-web-designing" target="_blank">Php Development</a></span>,<span style="mso-spacerun: yes;"> </span><span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/website-designing" target="_blank">Website designing</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/open-source-wordpress-joomla-oscommerce-customisation" target="_blank">Open Source customisation</a></span>. <span style="text-decoration: underline;"><a href="http://dhanashree.com/" target="_blank">Dhanashree Inc</a> </span>can be our <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/offshore-website-designing-company" target="_blank">offshore development company</a></span> / </span><a href="http://dhanashree.com/web-designing-outsource-advantages" target="_blank"><span style="font-size: 11pt; font-family: Calibri;">outsourcing</span></a><span style="font-size: 11pt; font-family: Calibri;"> <span style="text-decoration: underline;"><a href="http://dhanashree.com/dhanashree-web-development-profile" target="_blank">web development company</a></span>, <span style="text-decoration: underline;"><a href="http://dhanashree.com/web-development-services/dedicated-php-dotnet-developer" target="_blank">hire dedicated web programmers</a></span>.</span></span></p>
<p class="MsoNormal" style="margin: 0in 0in 10pt;"><span lang="EN-IN"><span style="font-size: 11pt; font-family: Calibri;">Above information is for knowledge sharing<span style="mso-spacerun: yes;"> </span>if you have problem / issue / suggestion please intimate us with details for proper and prompt action.</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://techinsight.dhanashree.com/dot-net-framework-3-5-c-vb-net-language-improvements-automatic-properties-object-initializers-collection-initializers-lambda-expression-anonymous-type/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

