New feature No.1 in C# 6.0
1. using Static
This is a new concept in C# 6.0 that allows us to use any class that is static as a namespace that is very usefull for every developer in that code file where we need to call the static methods from a static class like in a number of times we need to call many methods from Convert.ToInt32() or Console.Write(),Console.WriteLine() so we need to write the class name first then the method name every time in C# 5.0. In C# 6.0 however Microsoft announced a new behavior to our cs compiler that allows me to call all the static methods from the static class without the name of the classes because now we need to first use our static class name in starting with all the namespaces.
- In C# 5.0
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace TestNewCSharp6
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Enter first value ");
- int val1 =Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("Enter next value ");
- int val2 = Convert.ToInt32(Console.ReadLine());
- Console.WriteLine("sum : {0}", (val1 + val2));
- Console.ReadLine();
- }
- }
- }
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Convert;
- using System.Console;
- namespace Project1
- {
- class Program
- {
- static void Main(string[] args)
- {
- WriteLine("Enter first value ");
- int val1 = ToInt32(ReadLine());
- WriteLine("Enter next value ");
- int val2 = ToInt32(ReadLine());
- WriteLine("sum : {0}", (val1+val2));
- ReadLine();
- }
- }
- }
In C# 6.0
Code in 5.0
Output
Comments
Post a Comment