Tip #012
using static
About this tip
using static calls static members without the class name. Fits Console and Math. using static imports a type's static members, so Console.WriteLine becomes WriteLine and Math.Sqrt becomes Sqrt. It is available since C# 6. The key line is using static System.Console in usingstatic.cs.
Did this tip save you some time? Consider buying me a coffee to fuel the next one.
Buy me a coffeeCode
using static System.Console;using static System.Math;
WriteLine(Sqrt(144));WriteLine(Max(3, 7));WriteLine(Pow(2, 10));Output
$ dotnet run usingstatic.cs1271024