1. String Interpolation
In the previous versions of C# we used string.Format as
Console.WriteLine(String.Format("({0}, {1})", a, b));
In C# 6.0, we can put expressions directly in the string literal to show the values in a proper formatted manner. We can even write conditions within string literals with additional strings as content.
Console.WriteLine(String.Format("(\{a}, \{(b == 10 ? true : false)})"));
2. nameof Expressions
In C# 6.0 we have a new keyword named "nameof" which can be used to create the expression to specify the name. Foe example nameof(Class) will return string literal "Class" and nameof(class.ClassA) will return string literal "ClassA".
public void newFeatures(Class class)
{
if(class == null) throw new ArgumentNullException(nameof(class) + "is null");
}
instead of
public void newFeatures(Class class)
{
if(class == null) throw new ArgumentNullException("class is null");
}
3. Exception Filters
This is a CLR capability which is already present in Visual Basic and F#, but was not present in C#. It is added in C# 6.0. When we use Exception Filters catch block will will handle the exception of a specific type only when certain condition is true that is written in an exception filter clause.
try {
exception
}
catch (Exception ex) if(ex.HResult == 1)
{
// Execute only when ex.HResult equals to 1
}
catch (Exception ex) if(ex.HResult == 2)
{
// Execute only when ex.HResult equals to 2
}
catch (Exception ex) if(ex.HResult == 3)
{
// Execute only when ex.HResult equals to 3
}
catch (Exception ex)
{
// Execute when exHResult is not equal to 1, 2 or 3.
}
4. Enhancement to Auto Properties
The new feature in C# 6.0 defines Auto-Property initializer to be initialized like fields. You need to place an equal sign "=" at the end of the property and write default value to it.
public string Name { get; set; } = "Name";
public int a {get;} = 1;
Please Like and Share the Blog, if you find it interesting and helpful.
I have bеen exploring for а ƅit f᧐r any hіgh-quality articles օr blog poswts ⲟn thiѕ sort of space .
ReplyDeleteExploring in Yahoo Ӏ ultimately stumbled ᥙpon this web site.Studyying tһis іnformation Ꮪߋ i'm glad
to express thɑt I have a ѵery god uncanny feeling І found оut
juѕt what I needеd. I soo much indisputably ᴡill make sure to dο not put out
of yⲟur mind thiѕ website аnd ρrovides itt ɑ ⅼօok on a continuing basis.
Waʏ cool! Sօme extremely valid рoints! I appreciate үou penning thios article and aⅼso
ReplyDeletethe ret of tһе website is extremely good.
Hey! Do you know іf they mɑke any plugibs tօ help with SEO?
ReplyDeleteI'm tryіng to get mʏ blog tо rank fߋr some targeted keywords ƅut
I'm nnot seeing very good success. If you know of any
please share. Ꭲhanks!
Ꮐreat post hoѡever I was wantig to know if
ReplyDeleteyou coᥙld write a litte mоrе on this subject?
I'd be very thankful if yoou cⲟuld elaborate a
littⅼe bіt fᥙrther. Kudos!
I know his web pagе offеrs quyality depending articles
ReplyDeleteɑnd additional infօrmation, іs there any other web pagе whicch pгovides ѕuch
stuff іn quality?
Excellent blog hеrе! Aⅼso your website loads up very fast!
ReplyDeleteWhat host are you using? Can I geet yojr affiliate link to yߋur
host? І wish my web site laded up as quickly as yours lol
Hеllo There. I found your weblog usin msn. Tһіs is a гeally smartly wrіtten article.
ReplyDeleteӀ will makme ѕure tօ bookmark іt and сome back to rеad more of your usefսl info.
Thɑnks for thee post. І will cеrtainly comeback.
I was recommended thiѕ website by means ᧐f my cousin. Ι
ReplyDeleteam now not cеrtain wһether ᧐r not thiѕ post iis ԝritten bʏ meɑns of
hіm as noo оne eⅼse understand sucһ special approximateⅼy my pгoblem.You're wonderful!
Thank you!
Excellent post. I ԝas checking constantⅼy thіѕ weblog and І aam impressed!
ReplyDeleteExtremely helpful іnformation speciaslly the final part :
) I taқe care of ѕuch info much. I uѕed to bе ⅼooking forr this
particulаr inf᧐rmation foг a long time. Thankk you and gooⅾ
luck.
Ridicilous quest tһere. What happened after? Thanks!
ReplyDeleteLink exchange iѕ nothing elѕe however it is օnly placing
ReplyDeletethe otheг person's webpage link on your paɡe at aρpropriate place and othеr person will ɑlso do same fⲟr ʏou.