skip to content
Khalid Abuhakmeh logo Khalid Abuhakmeh

using static

C# 6

Code card: using static. Program output: 12 / 7 / 1024

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 coffee
usingstatic.cs
using static System.Console;
using static System.Math;
WriteLine(Sqrt(144));
WriteLine(Max(3, 7));
WriteLine(Pow(2, 10));
Output
$ dotnet run usingstatic.cs
12
7
1024