A Small Variation


Although all of the programs in this book will use it, the statement

 using System;

at the start of the first example program is not technically needed. It is, however, a valuable convenience. The reason it’s not necessary is that in C# you can always fully qualify a name with the namespace to which it belongs. For example, the line

 Console.WriteLine("A simple C# program.");

can be rewritten as

 System.Console.WriteLine("A simple C# program.");

Thus, the first example could be recoded as shown here:

 // This version does not include the using System statement. class Example {   // A C# program begins with a call to Main().   public static void Main() {     // Here, Console.WriteLine is fully qualified.     System.Console.WriteLine("A simple C# program.");   } }

Since it is quite tedious to always specify the System namespace whenever a member of that namespace is used, most C# programmers include the using System statement at the top of their programs, as will all of the programs in this book. It is important to understand, however, that you can explicitly qualify a name with its namespace if needed.




C# 2.0(c) The Complete Reference
C# 2.0: The Complete Reference (Complete Reference Series)
ISBN: 0072262095
EAN: 2147483647
Year: 2006
Pages: 300

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net