Reputation: 953
The C# doc on the using
directive says
The
using
directive allows you to use types defined in a namespace without specifying the fully qualified namespace of that type.
I understood this to mean that if you want to use System.Console
, you have two options -- either
using System
directive in your code which allows you to refer to System.Console
simply as Console
; or,System.Console
-- i.e. refer to System.Console
as System.Console
.Yet, I have the following C# code in Visual Studio Code and it works even though I didn't include a using System
directive and even though I refer to System.Console
as just Console
Console.WriteLine("Hello World!");
List<String> names = ["Alice", "Bob", "Eve"];
foreach (String name in names) {
Console.WriteLine($"Hello {name}!");
}
Console
lives in the System
namespaceList
lives in the System.Collections.Generic
namespaceI am neither fully-qualifying System.Console
nor did I include a using System
directive.
Similarly for List
.
Yet, the code runs fine and prints the following the console:
Hello World!
Hello Alice!
Hello Bob!
Hello Eve!
Upvotes: 1
Views: 46