Thursday, February 7, 2008

C# 3.5 - Properties Shorthand

I must tell you if today your C# knowledge is not up to date then you might face tough time with future versions of the language. Microsoft developers will keep on adding new things ranging from entirely new features like LINQ to something like Implicit types or Object initializations. Last two features that I've mentioned are due to LINQ and secondly they provide some kind of syntactical sugar for developers. In future, VB.NET and C# will take entirely different paths. C# will become more performance oriented and VB.NET more developer friendly. VB.NET will target UI where as C# will mostly be used as class libraries. I am not sure when will this happen but it will happen soon [trust my Microsoft contacts :) ]

Let me show you how property shorthand feature of C# works from inside. We will start of with a simple console application and add code as needed.

Adding property shorthand to your code
Type prop in code window and let intellisense jump in. Then select "prop" and press Tab 2 times. A property shorthand will appear
.

Complete your class definition
Add 3 shorthand properties and one normal property. Your final class definition will look like this



















Create a class that will use Customer object.
Main() method in Program.cs would be enough for us
,













And the output is as expected,




Let us examine the IL that is generated for this managed assembly. Below are two images one with IL showing members of Customer class and next one with one method expanded.


For the properties that we created with shorthand, C# compiler added a backing field for each shorthand property in this format,
k_BackingField: private TypeOfShrtHandProperty

get_FirstName method expanded
Image shown below looks at the IL generated for get_FirstName method. Second IL instruction 'ldflf' i.e. Load Field, works with backing field created by the compiler. set_FirstName() also uses this backing field.

Don't expect that these shorthands will support validations etc. These are simple properties and just adds thread safety over using class variables directly. If we don't want any thread safely and no validations, then we should not provide properties. I guess this is a cool new feature but unless you understand how it works inside you will not able to fully utilize it.

Next I'll add a small post related to introduction of partial methods in C#. I am down with Viral from last few days but today I am feeling quite well. I hope! to get well soon.

~ILdasm rOcKs~

31 comments:

Anonymous said...

[B]NZBsRus.com[/B]
Escape Slow Downloads With NZB Files You Can Instantly Find High Quality Movies, Console Games, MP3 Albums, Applications and Download Them @ Electric Rates

[URL=http://www.nzbsrus.com][B]Usenet[/B][/URL]

Anonymous said...

[B]NZBsRus.com[/B]
Dismiss Slow Downloads With NZB Files You Can Hastily Search HD Movies, Games, MP3s, Software and Download Them at Flying Speeds

[URL=http://www.nzbsrus.com][B]Newsgroup Search[/B][/URL]

Anonymous said...

Aid to pass the rude with two backs casinos? examine this immature [url=http://www.realcazinoz.com]casino[/url] guide and steppe online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also probe our belated [url=http://freecasinogames2010.webs.com]casino[/url] mastery at http://freecasinogames2010.webs.com and prostrate bona fide tangled bread !
another friendless [url=http://www.ttittancasino.com]casino spiele[/url] purlieus is www.ttittancasino.com , because german gamblers, protect not rococo online casino bonus.

Anonymous said...

Validate Our Crestfallen Prices at www.Pharmashack.com, The Famed [b][url=http://www.pharmashack.com]Online Dispensary [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Gather up Great Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Be subjected to a Vital Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] In stick of Your Meat ! We Yield up Swap identification [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !

Anonymous said...

Thanks for the details...it was helpful

Anonymous said...

Genial post and this post helped me alot in my college assignement. Say thank you you seeking your information.

Anonymous said...

Someone deleted several links from quickshare and zshare ...

From now, we will use www.tinyurlalternative.com as our main [url=http://www.tinyurlalternative.com]url shortener[/url], so every link will be there and visible for everyone.

You can choose from many great [url=http://kfc.ms]short url[/url] address like:

kfc.ms easysharelink.info jumpme.info megauploadlink.info megavideolink.info mygamelink.info myrapidsharelink.info mytorrentlink.info myurlshortener.com mywarezlink.info urlredirect.info urlshrinker.info weblinkshortener.com youtubelink.info and many others.

They have over 60 other available domains and the [url=http://myurlshortener.com]url shortener[/url] service work properly for free without any registration needed.

So we think it is good notion and propose you to use [url=http://urlredirect.info]url redirect[/url] service too!

Thank you.

Anonymous said...

Good post and this fill someone in on helped me alot in my college assignement. Gratefulness you for your information.

Anonymous said...

[b]Website Traffic[/b]

A new way to get traffic to your website. Not only will you get loads of [url=http://www.fastpixeltraffic.com/]traffic[/url] more and more everyday you will also get backlinks with all the other sites on the [url=http://www.fastpixeltraffic.com/]grid[/url] getting you a better search engine ranking which will get you even more [url=http://www.fastpixeltraffic.com/]website traffic[/url].Get on the pixel grid today and let the traffic come to you.Taking the internet by storm.The new way to advertise.

Visit: http://www.fastpixeltraffic.com/

generic viagra said...

Nice work very professional weblog!!
buy viagra
viagra online
thanks for sharing!!!

Anonymous said...

Good post and this enter helped me alot in my college assignement. Thank you seeking your information.

Anonymous said...

[url=http://www.hadigel.net/indir/indir.asp?id=4892]fotomontaj indir[/url]

Anonymous said...

Sheena is the greatest!?

Daryl

viagra online without prescription said...

Your blog is outrageous! I mean, Ive never been so entertained by anything in my life! Your vids are perfect for this. I mean, how did you manage to find something that matches your style of writing so well? Im really happy I started reading this today. Youve got a follower in me for sure!

Anonymous said...

xanax depression valor alprazolam 0 5mg - buy generic xanax online

Anonymous said...

Message35, http://www.arlo.net/massacree/ viagra online in uk, zjma2, http://www.arlo.net/fccgb/ buy viagra without prescription, jisf3, http://www.arlo.net/fccgb/notes/ buy generic viagra, xjrl9, http://www.arlo.net/bytes/ order cheap viagra, ovzz4, http://www.arlo.net/live/ viagra

Anonymous said...

top [url=http://www.001casino.com/]casino bonus[/url] brake the latest [url=http://www.realcazinoz.com/]casino games[/url] autonomous no deposit bonus at the chief [url=http://www.baywatchcasino.com/]unshackle casino games
[/url].

Anonymous said...

top [url=http://www.001casino.com/]casino online[/url] brake the latest [url=http://www.casinolasvegass.com/]online casino[/url] manumitted no deposit bonus at the leading [url=http://www.baywatchcasino.com/]spare casino games
[/url].

Anonymous said...

http://site.ru - [url=http://site.ru]site[/url] site
site

Anonymous said...

john deere 4100 ebook tractor manual http://audiobookscollection.co.uk/de/Structures-and-Beyond-The-Cartography-of-Syntactic-Structures/p224189/ ama manual of style ebook [url=http://audiobookscollection.co.uk/fr/Questions-sociales/c1362/]end zone book ebook[/url] ebook newfangled fariy tales

Anonymous said...

download ebook on wordpress http://audiobookscollection.co.uk/es/Chasing-Trouble/p174303/ linq ebook [url=http://audiobookscollection.co.uk/fr/Globalization-Wages-and-the-Quality-of-Jobs-Five-Country-Studies/p223026/]intro machine learning alpaydin ebook torrent[/url] stokstad art history ebook

Anonymous said...

ebook snapshots from the wedding http://audiobooksworld.co.uk/de/Giant-Axonal-Neuropathy-A-Bibliography-and-Dictionary-for-Physicians-Patients-and-Genome-Researchers/p226490/ turnkey ebook website [url=http://audiobooksworld.co.uk/es/authors/?letter=Zn]wyckoff method ebook[/url] str8te boys ebook torrent

Anonymous said...

paradox software http://buyoem.co.uk/category-100-102/Business?page=7 sunguard software [url=http://buyoem.co.uk/product-35372/3herosoft-iPod-to-Computer-Transfer-3-8-MacOSX]optipix software downloads[/url] paper doll software
[url=http://buyoem.co.uk/es/category-100-111/Herramientas-de-sistema]Herramientas de sistema - Software Store[/url] gps software nz
[url=http://buyoem.co.uk/category-100-114/Other?page=6][img]http://buyoem.co.uk/image/4.gif[/img][/url]

Anonymous said...

Hello. Facebook takes a [url=http://www.casinogames.gd]no deposit casino bonus[/url] stick on 888 casino mete out: Facebook is expanding its efforts to push aside rash real-money gaming to millions of British users after announcing a give out with the online gambling found search for 888 Holdings.And Bye.

Anonymous said...

system booster software http://buysoftwareonline.co.uk/product-10235/SpotAuditor-3-6-6 act software consulting detroit [url=http://buysoftwareonline.co.uk/product-16560/Folder-icon-Maker-X-Mac]template word 2003 install software[/url] mdsolids 3.2 software free
[url=http://buysoftwareonline.co.uk/category-100-106/Server-Software?page=3]Server Software - Software Store[/url] best photo editing software available
[url=http://buysoftwareonline.co.uk/de/product-37391/Easy-MPEG-AVI-DIVX-WMV-RM-to-DVD-1-6][img]http://buyoem.co.uk/image/4.gif[/img][/url]

Anonymous said...

sxs software http://buysoftwareonline.co.uk/category-7/Programming-and-Development symantec hp suretape backup software [url=http://buysoftwareonline.co.uk/it/product-37131/RAC-Server-3-3]math software linux download[/url] serif photoplus editing software
[url=http://buysoftwareonline.co.uk/product-36586/Microsoft-Windows-7-Ultimate-x32-Spanish]Microsoft Windows 7 Ultimate x32 Spanish - Software Store[/url] windows media player software
[url=http://buysoftwareonline.co.uk/category-100-112/Multimedia-and-Entertainment?page=120][img]http://buyoem.co.uk/image/4.gif[/img][/url]

Anonymous said...

[url=http://englandpharmacy.co.uk/products/zestril.htm][img]http://onlinemedistore.com/6.jpg[/img][/url]
fuquay varina n c kroger pharmacy http://englandpharmacy.co.uk/products/plendil.htm matt connell pharmacy director [url=http://englandpharmacy.co.uk/categories/cholesterol.htm]cvs pharmacy wakefield ma phone[/url]
mississippi board of pharmacy http://englandpharmacy.co.uk/products/torsemide.htm pharmacy ohio [url=http://englandpharmacy.co.uk/products/kamasutra-longlast-condoms.htm]kamasutra longlast condoms[/url]
how much does a pharmacy tech earn http://englandpharmacy.co.uk/products/erectalis.htm online pharmacy degree [url=http://englandpharmacy.co.uk/products/endep.htm]long term care pharmacy providers[/url]
purchase altace online rolipram pharmacy http://englandpharmacy.co.uk/products/emsam.htm belmont pharmacy school and condo and nashville [url=http://englandpharmacy.co.uk/products/ventolin.htm]ventolin[/url]

Anonymous said...

free dating site romanians [url=http://freeinternetdating.info/friendship/friendship-valentines-gifs-and-cartoons]friendship valentines gifs and cartoons[/url] dating old piano
transexual dating new jersey http://freeinternetdating.info/love/summary-ofto-sir-with-love canadian pinoy dating
talking dating relationship [url=http://freeinternetdating.info/bride/russain-bride-visa-requirement-to-usa]best dating template sites[/url] biltmore pocketwatch dating

Anonymous said...

An outstanding share! I've just forwarded this onto a co-worker who was conducting a little research on this. And he in fact ordered me breakfast because I found it for him... lol. So allow me to reword this.... Thanks for the meal!! But yeah, thanx for spending the time to discuss this matter here on your web page.

Feel free to surf to my weblog - traffic exchange

Anonymous said...

you're really a excellent webmaster. The site loading velocity is amazing. It seems that you are doing any unique trick. In addition, The contents are masterwork. you have done a wonderful job in this matter!

Feel free to surf to my web site: web traffic exchange

Anonymous said...

membership lists for dating sites http://loveepicentre.com/success_stories/ black american dating asian americans
dating prison women [url=http://loveepicentre.com/contact/]ghana dating dites[/url] britney spears dating paparazzi
dating tauranga [url=http://loveepicentre.com/]romanian men dating[/url] free dating site in american [url=http://loveepicentre.com/user/rahulkrishnarbk/]rahulkrishnarbk[/url] bolivian dating sites