C# 0 The Complete Reference


Ctr  is specified for  Counter



Download 4,07 Mb.
Pdf ko'rish
bet564/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   560   561   562   563   564   565   566   567   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Ctr

 is specified for 



Counter

 by the following line:

using Ctr = Counter;

Then, inside 



Main( )

, this alias is used to qualify 



CountDown

, as shown here:

Ctr::CountDown cd1 = new Ctr::CountDown(10);

The use of the 



::

 qualifier removes the ambiguity because it specifies that the 



CountDown

 in 


Ctr

 (which stands for 



Counter

) is desired, and the program now compiles.

You can use the 

::

 qualifier to refer to the global namespace by using the predefined 

identifier

global

. For example, in the following program, a class called 



CountDown

 is 


declared in both the 

Counter

 namespace and in the global namespace. To access the 

version of 

CountDown

 in the global namespace, the predefined alias 



global

 is used.

// Use the global alias.

using System;

// Give Counter an alias called Ctr.

using Ctr = Counter;

// Declare a namespace for counters.

namespace Counter {

  // A simple countdown counter.

  class CountDown {

    int val;

    public CountDown(int n) {

      val = n;

    }


    // ...

  }


www.freepdf-books.com


PART I

C h a p t e r   1 6 :  

  N a m e s p a c e s ,   t h e   P r e p r o c e s s o r ,   a n d   A s s e m b l i e s  

451


PART IPART I

}

// Declare another class called CountDown, which



// is in the global namespace.

class CountDown {

  int val;

  public CountDown(int n) {

    val = n;

  }


  // ...

}

class GlobalAliasQualifierDemo {



  static void Main() {

    // Here, the :: qualifier tells the compiler

    // to use the CountDown in the Counter namespace.

    Ctr::CountDown cd1 = new Ctr::CountDown(10);

    // Next, create CountDown object from global namespace.

    global::CountDown cd2 = new global::CountDown(10);

    // ...

  }


}

Notice how the 



global

 identifier is used to access the version of 



CountDown

 in the default 

namespace:

global::CountDown cd2 = new global::CountDown(10);

This same general approach can be generalized to any situation in which you need to 

specify the default namespace.

One final point: You can also use the namespace alias qualifier with 

extern

 aliases, 

which are described in Chapter 20.


Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   560   561   562   563   564   565   566   567   ...   1096




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish