C# 6.0 Features

 



string interpolation - It is mainly introduced to remove string. Format. It is a new way of concatenating strings, manipulating strings and formatting strings



Null conditional operator - this is used to avoid nullreference exception like object reference not set to an instance of an object. When we use this operator : it returns null as a value and wont throw any exception.




Auto-property Initializer - This is used to set the properties values when they are declared at their place itself. Before this, we should use class constructor to initialize the properties to their default values.



Dictionary/Index initializers - Before c#6.0, if we create Dictionary object then if you want to add any items into it, then we need to use Add() method. Now in c#6.0, we can do it similar to collection or object initializer way.


Expression-body-function : This is nothing but similar to writing normal  code inside methods only this here we dont use "RETURN" keyword to return anything. Here we need to use lamba operator and dont not use "RETURN" keyword inside lamba operator expression.This is nothng but a shortcut implementation of the method thats it.




using static - Use this if you want to access built-in "STATIC "class members without prefixing with class. So declare those class in the import section like "using static System.Console" . Now you no need to type like "Console.WriteLine("Hello"); instead you can directly type "WriteLine("Hello"):

nameOf - Sometimes we need to print the name of declared variables as it is then we use "nameof"



exception-filter : This means that now we can decide whether catch block should be executed or not based on boolen expression given immdieatley after catch block



async and await in catch block - This is similar to asyn and await functionality. Instead of giving async it in try block, we are giving it in catch block. This functionality is added for catch block also becuase if there is logging mechanism that takes long time to log the errors then without asyn, the main thread should untill the catch block completes and main thread will freeze at this time. Hence we need async in catch and final block.




Comments

Popular posts from this blog

Understanding Collection and Object Initializer

How to execute Javascript in VS code