There are plenty of blogs and articles already posted about C# 6.0 new features. But I observed there are some changes from the features in the preview and newly shipped with Visual Studio 2015 RTM (of course some improvements are based on feedback from the preview). In this article, I'm trying to address those changes as well as I will also describe new features.
The following is the list of enhancement delivered in the RTM version of C# 6.0 (excluding VB enhancements that were specified in the source, also I have added quick samples to illustrate the enhancements).
| Feature | Example |
| Auto-property initializers | public int X { get; set; } = x; |
| Read-only auto-properties | public int Y { get; } = y; |
| Constructor assignment to getter-only autoprops | public DemoClass{ Y = 15; } |
| Static imports | using static System.Console; … Write(4); |
| Index initializer | > new JObject { ["x"] = 3 } > var numbers = new Dictionary<int, string> { [7] = "seven", [9] = "nine", [13] = "thirteen" }; |
| Await in catch/finally | try … catch { await … } finally { await … } |
| Exception filters | catch(E e) when (e.Count > 5) { … } |
| Partial interfaces | Partial Interface I1 |
| Multiline string literals | "Hello<newline>World" |
| Expression-bodied members | public double Dist => Sqrt(X * X + Y * Y); |
| Null-conditional operators | customer?.Orders?[5] |
| String interpolation | $"{p.Name} is {p.Age} years old." |
| nameof operator | string s = nameof(Console.Write); |
| #pragma | #Disable Warning BC40008 |
| Read-write props can implement read-only interface properties | <"In my TODO items"> |
| #Region inside methods | public void TestMethod() { #region MyRegion #endregion } |
| CRef and parameter name | /// <summary> /// Initialize with <see cref="Program(DateTime)"/> /// </summary> public Program(DateTime timestamp) { } |
| Extension Add in collection initializers | See the explained example below. |
| Improved overload resolution | <"In my TODO items"> |
Most of the feature enhancements specified above are self explanatory. So I'll be explaining only the interesting ones that need explanation.
Properties Enhancements
We have a couple of enhancements in the Auto properties. With the new enhancements the compiler generated the required code and saved some developer's time. Now the properties are:
- public class Person
- {
- // Readonly properties are not allowed to be initialized in Constructor
- public int Id { get; }
- public Person()
- {
- // Initialzing the readonly property.
- this.Id = -1;
- }
- // Initialize the property right at the declaration
- public string Name { get; set; } = "Jhon Doe";
- public int Age { get; set; }
- public string Title { get; set; }
- }
Static Imports and Extension methods
Now C# allows importation of static members of another class without using the class name. So they can be used directly in another class. This feature is extended to include the Extension methods. Also the improvement was done with Using. Now one must use the Static keyword to import the static members.
For example:
- using System.Text;
- using System.Threading.Tasks;
- using static System.Console;
- using static System.Linq.Enumerable;
- public class Demo
- {
- public void Print()
- {
- var cultures = new string[] { null, "en-NZ", "en-US", "en-AU", "en-GB" };
- Write("The static methods are directly available.");
- // Here Range() is static so only simple static methods are allowed to use.
- // Extensions are static
- // but they are not be allowed to use directly.
- // This is taken care of very carefully to keep the
- // separation in these two types of features.
- WriteLine(Range(0, 10).Where(x => x % 2 == 0));
- }
- }
This looks interesting but this feature already exists in VB.NET, surely it was brought back home to C#. It could be value added where a Generic collection must be initialized with complex types. Here's a sample of how it works.
For example the following is a simple entity representing a complex type (let's assume).
- public class Person
- {
- public int Id { get; set; }
- public string Name { get; set; }
- public int Age { get; set; }
- public string Title { get; set; }
- }
- public static class Extensions
- {
- public static void Add(this List<Person> source, int id, string name, int age, string title)
- {
- source.Add(new Person {
- Id = id,
- Name = name,
- Title = title,
- Age = age
- });
- }
- }
- List<Person> List = new List<Person>()
- {
- { 1, "Ramesh", 22, "Mr." },
- { 2, "Julia", 24, "Ms" },
- { 3, "Paula", 12, "Mrs." },
- };
I hope most of us will be enjoying these features though it will take some time to decide if they are a handy feature. Those that are marked as a “TODO” item, I'll be working on exploring them and may be writing about them in a future article.

Yashwanth MuthineniPosted Aug 14, 2015, 12:49 AM
good one sir
Vaikesh K PPosted Aug 13, 2015, 12:54 AM
Nice Work
Santhakumar MunuswamyPosted Aug 12, 2015, 2:59 PM
Good Article. Thanks for sharing
Chervine BhiwooPosted Aug 12, 2015, 10:51 AM
Nice. Thanks!
Gopi ChandPosted Aug 12, 2015, 7:25 AM
Good work
Van LaiPosted Aug 11, 2015, 10:15 PM
Informative! Thank you.
Amit ChoudharyPosted Aug 11, 2015, 7:10 PM
Thanks Guys... If there's anything you want me to explore about VS2015, C#, Windows 10, Universal Apps etc. Let me know.
RakeshPosted Aug 11, 2015, 2:44 PM
Good share
Nilesh JadavPosted Aug 11, 2015, 9:55 AM
good share sir
Sibeesh VenuPosted Aug 11, 2015, 6:16 AM
Nice Share
Pankaj Kumar ChoudharyPosted Aug 11, 2015, 5:31 AM
Nice Explain Sir........
Former memberPosted Aug 11, 2015, 4:31 AM
supper
Mohammed IbrahimPosted Aug 11, 2015, 3:39 AM
nice
Rajeesh MenothPosted Aug 11, 2015, 3:32 AM
Superb..Thanks for sharing..