C# 6.0 New Features: Index Initializers
Another new feature although I would say syntax is Index Initializer. This features was although introduced in C# 3.0 and C# 6.0 provides just more concise syntax over that.
What’s new in C# 6.0 – Tutorials
Another new feature although I would say syntax is Index Initializer. This features was although introduced in C# 3.0 and C# 6.0 provides just more concise syntax over that.
C# 6.0 introduces the concept of auto property initializer as we discussed in another blog post here
Also another feature is deferring the initialization of read-only property from constructor. This feature is available in most recent version of CTP
Since its release, C# has travelled a long journey from being a imperative language to a declarative one. With this journey the way we use to write methods have also changed a lot. Lets try to understand the journey of a method from C# 1.0 to 6.0
This is how we use to write methods in C# 1.0 .These were called named methods.Also you can see how a delegate is using a named method to print a value to console.
Let’s go in flashback and try to understand how properties evolved in .Net.
Properties are wrapper over fields which controls the way our fields should be accessed and modified.
Static in C#:
Static is a compiler reserved keyword in C#, which can be applied to any member of a class i.e. well Fields, methods, classes, Properties, Events or to a class itself as well.
There will be only one copy of a member variable declared as static. Each object has its own copy of instance variables whereas static variables are shared across objects.
The most common programming practice is to catch exceptions and log them. Logging involves IO since we usually log into files or database. IO operations are usually expensive in terms of performance which means that in a serviced kind of environment, the end user who is waiting for a response is actually being kept waiting for logging messages as well.
Many times in code we need to write the name of class member. Usually while throwing validation exceptions from server or firing PropertyChanged events in case of 2 way bindings. C# 6.0 introduces nameOf expression
Prior to C# 6.0 String concatenation sometimes became challenging in older versions of c#, primarily since we need to write numeric placeholders and than variables in same order. Consider below example
Again this is something which was supported in VB but have been introduced into c# as well.
I have seen in recent past Microsoft has brought back lot of legacy VB stuff into C#. If you remember VB provides with clause , this features bring back memory of that.