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.
And the output is as expected,
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.