Hello World

Using Directives

In our previous example, we used the following code to write "Hello World" to the Console output:

Console.WriteLine("Hello World");

But, where does Console come from and how can we use it? To be able to use the Console class in our program, we needed to add a using directive at the top of our program file:

using System;

 

Applications built on the .NET Framework organise their classes into containers called Namespaces. In our example, the Console class belongs to the System namespace. There are many namespaces provided by the .NET Framework, here are some examples:

  • System.Collections - Contains classes for creating lists and dictionaries for storing data.
  • System.IO - Contains classes used to read and write files, and other disk operations.
  • System.Xml - Contains classes for using XML.

 

If you don't place a using directive in your code, you can still use classes that belong to the namespace by using a fully-qualified name:

public class Program { public static...

 

Page 5 of 13