Category Archives: C# 7

C# 7 – Expression bodied members

Expression-bodied “fat arrow” syntax for methods. In C# 6, expression bodied fat-arrow syntax for methods, read-only properties, operators, and indexers. C# 7 extends this to constructors. read/write properties and finalizers. Expression bodies members   public class Employee { string name; … Continue reading

Posted in C# 7 | Leave a comment

C# 7 – local methods

C# 7 – local methods   void WriteCubes() { Console.WriteLine(Cube(3)); Console.WriteLine(Cube(4)); Console.WriteLine(Cube(5)); int Cube (int value) => value * value * value; }

Posted in C# 7 | Leave a comment

C# 7 – Introducing variables on the fly with the ‘is’ operator

This is called pattern variables. C# 7 – Variables on the fly w/ is operator   void SomeMethod(object x) { if (x is an int) { Console.WriteLine(x); } } — The switch statement also supports patterns.     switch (x) { … Continue reading

Posted in C# 7 | Leave a comment

C# 7 – Out variables & discards

In C# 7, you can declare out variables on the fly:     bool success_ = int.TryParse(“8888”, out int result); Console.WriteLine(result); You can also discard out parameters using the underscore parameter. SomeMethod(out  _, out  _, out int x); Console.WriteLine(x);

Posted in C# 7 | Leave a comment