Wednesday, April 18, 2007

Properties in .NET

Last few days have been extremely hectic for me. We have been working with pace to set the tone up for the new HiText reporting tool that we @ EITS are planning to use to generate our reports.

Finally we got it to work. And in the mean time, I learnt quite a new concepts in the process itself. Be it Reflection, Be it Properties, Dynamically loading and calling assemblies, creating templates to use with Visual Studio IDE, tweeking IDE to implement my own Intellisense and many more..

Due to the lack of time, I could not update the place as frequently as before. So once I got some time out of work, I concentrated back on putting something up here.

So here is the first one from me:



The PROPERTIES in .NET are said to be faster than normal user defined functions.

But strange enough (to me atleast), the properties that are defined at the class level, at the grassroot level are implemented as functions itself.

Just to confirm the same.....you could create a simple class with a few properties defined. Compile it and then try checking the output in the ILDASM.

I came across this fact when I was playing around with Reflection and Invoking methods and getting properties to return values by just specifying the names of the properties as string.

Ususally any property in C# is written with two methods (get & set) and this property is in turn implements as two seperate functions. For example if we create a property called Prop1 with methods get and set defined, the they are at root level implemented as the following two functions:
1. GET - get_Prop1()
2. SET - set_Prop1()

I accidentally came across the fact when the compiler told me that I can not create function named get_Prop1 or set_Prop1..........as they already exist ?????????????

After a bit of exploration, here is the result .NET properties are implemented as functions itself. If so then how come using Properties be better than using Functions.

Well the .NET compiler are built up and are implemented in such a way so as to give preceeedence to these get and set functions over all other functions and hense they are faster. No special concerns about the same.


Hope this helps someone in there works.....

-- Ashutosh Vyas

No comments:

Post a Comment