In today’s newsletter we are going to discuss following features of C# 10
Lambda expressions
Extending properties
Global using statements
File scoped namespaces
Structs got the freedom
Seal .ToString() for records
Constant interpolated strings
1. Lambda Expressions
Lambda expressions are used to create anonymous functions , I love to use them for simple getter/setters e.g. GetFullName , Get Address etc. But lambdas have limitations with var types which were entertained in C# 10.
2. Extending Properties
Extending property was introduced in C# 8.0 , it allow a property sub patterns to reference nested members, for instance
3. Global Using Statements
You would have seen your code loaded with a lot of using statements at the top , and some of statements are repeated in multiple files. Since C# 10 now we can get rid of them through following ways
Either make a global class and define using statements in it
Include your using statements in .csproject file
4. File Scoped Namespaces
Now we can get rid of of namespaces and use file scoped namespaces.
5. Structs Got The Freedom
Now structs can have parameter less constructor opposite to previous one like this.
with
can be used for structs as well now
6. Seal .ToString() For Records
Before C# 10 we could not apply sealed keyword for ToString override against records but now we can do that.
Above mentioned feature was added in C# 10 for records.
7. Constant Interpolated Strings
If you don’t know let me remind you that we use $ with for our strings and then using { } we can define our variables that is string interpolation.
Previously we were unable to do this thing with constant strings , but now we can achieve it.
Whenever you’re ready , there are 3 ways I can help you
Promote yourself to 3000+ subscribers by sponsoring my Newsletter (Reach me at mwaseemzakir@gmail.com)
Become a Patron and get access to 100+ .NET Questions and Answers , I add 2-5 new questions every week
Get my FREE eBook from Gumroad that contains 30 .NET Tips (Downloaded by 2000+ and 85+ five star ratings)
Special Offers 📢
Ultimate ASP.NET Core Web API Second Edition - Premium Package
10% off with discount code: 9s6nuez
Thanks for news about C# 10. I give u ten points as master class trainee.