DotNET Schools

Blogs & Tutorials for Microsoft.NET and Leading web Technologies

C# 6 Modified & Removed Features

Using static classes as directive

Earlier Releases

  1. using System.Console;   
  2. using System.Convert;    
  • In the previous release we do not need to use the “static” keyword for using static classes as directive.
  • In previous version we can only use static classes and namespaces in as directive.

Current Release (VS 2015)

  1. using static System.Console;   
  2. using static System.Convert;    
  1. Now we need add static keyword to use static classes as directive.
  2. In previous release apart from namespace we can use static classes. But in current release (VS 2015) using static keyword we can include static classes & non static classes, too.

    For code snippet of Static Classes as directive visit here & for Non-Static classes as directive visit here.

Primary Constructors

Earlier Releases

  1. namespace PrimaryConstructorDemo   
  2. {   
  3. class PrimaryConstructorDemo(int employeeId, string empName, string empDesignation)   
  4. {   
  5. public int EmployeeId { get; } = employeeId;   
  6. public string EmployeeName { get; } = empName;   
  7. public string EmployeeDesignation { get;} = empDesignation;   
  8. }   
  9. }   

Current Release (VS 2015) 

  • This feature has been removed.

    constructors

Declaration expressions in C#

  • Removed in Visual Studio 2015 Latest Releases.

Out parameters in VB

  • Removed in Visual Studio 2015 Latest Releases.

Using Static Classes as Directive in C# 6

As we know that in C# 6 we can use static classes in using directive. To use static classes in using directive we use the following syntax:

Using static <StaticClassNameWithCompleteNameSpace>;

  1. using System;  
  2. using static System.Console;  
  3. using static System.Convert;  
  4.   
  5. namespace UsingStaticToPrintDay  
  6. {  
  7.     class Program  
  8.     {  
  9.         static void Main(string[] args)  
  10.         {  
  11.             try  
  12.             {  
  13.                 WriteLine("Enter you choice from 1-7 and it will print corresponding day of a week");  
  14.                 int choiceofday  = ToInt32(ReadLine());    
  15.                 //Cast int to Enum                
  16.                 string dayOfweek = Enum.GetName(typeof(DayOfWeek), choiceofday);  
  17.                 WriteLine(dayOfweek);                
  18.             }  
  19.             catch (Exception ex)  
  20.             {  
  21.                 WriteLine(ex.Message);  
  22.             }  
  23.              
  24.               
  25.         }  
  26.     }  
  27. }