15.01.2013 Views

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

Free-ebooks-library - Bahar Ali Khan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The :: token is used for namespace alias qualification. In this example, we qualify<br />

using the global namespace (this is most commonly seen in auto-generated code to<br />

avoid name conflicts):<br />

namespace N<br />

{<br />

class A<br />

{<br />

static void Main()<br />

{<br />

System.Console.WriteLine (new A.B());<br />

System.Console.WriteLine (new global::A.B());<br />

}<br />

public class B {}<br />

}<br />

}<br />

namespace A<br />

{<br />

class B {}<br />

}<br />

Here is an example of qualifying with an alias (adapted from the example in “Extern”<br />

on page 60):<br />

extern alias W1;<br />

extern alias W2;<br />

class Test<br />

{<br />

static void Main()<br />

{<br />

W1::Widgets.Widget w1 = new W1::Widgets.Widget();<br />

W2::Widgets.Widget w2 = new W2::Widgets.Widget();<br />

}<br />

}<br />

62 | Chapter 2: C# Language Basics

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!