AS we know that before C# 6 we use to include only namespaces as “using directive” But in C# 6 & C# 7 we can include static classes, enum, non-static classes & structs too as “using directive”.
In this code snippet I am going to show you a sample code for “using Struct as directive” so that you can aware about its syntax and usage. You may be interested in code snippet of,
1. 1. Using Static Classes as directive
2. 2. Using non-Static classes as directive
3. 3. Using Enum as directive
Below is the code snippet of “Using Struct as directive”,
- using static System.Drawing.Color;
- using static System.DateTime;
- using static System.Console;
-
- namespace UsingStructAsDirectiveinCSharp6n7
- {
- class Program
- {
- static void Main(string[] args)
- {
-
-
- var color =Red;
-
- var isLeapyear = IsLeapYear(2016);
-
- WriteLine($"Today is: " + Now.DayOfWeek);
-
- }
- }
- }
153