C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet553/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   549   550   551   552   553   554   555   556   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Declaring a Namespace

A namespace is declared using the 



namespace

 keyword. The general form of 



namespace

 is 


shown here:

namespace



name

 {

   // members



}

Here, 


name

 is the name of the namespace. A namespace declaration defines a scope. Anything 

declared immediately inside the namespace is in scope throughout the namespace. Within a 

namespace, you can declare classes, structures, delegates, enumerations, interfaces, or another 

namespace.

Here is an example of a 



namespace

 that creates a namespace called 



Counter

. It localizes 

the name used to implement a simple countdown counter class called 

CountDown

.

// Declare a namespace for counters.



namespace Counter {

  // A simple countdown counter.

  class CountDown {

    int val;

    public CountDown(int n) {

      val = n;

   }

    public void Reset(int n) {



      val = n;

    }


    public int Count() {

      if(val > 0) return val--;

      else return 0;

    }


  }

} // This is the end of the Counter namespace.

Notice how the class 

CountDown

 is declared within the scope defined by the 



Counter

namespace. To follow along with the example, put this code into a file called 



Counter.cs

.

Here is a program that demonstrates the use of the 



Counter

 namespace:

// Demonstrate the Counter namespace.

using System;

class NSDemo {

  static void Main() {

    // Notice how CountDown is qualified by Counter.

    Counter.CountDown cd1 = new Counter.CountDown(10);

    int i;

    do {


      i = cd1.Count();

      Console.Write(i + " ");

www.freepdf-books.com



Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   549   550   551   552   553   554   555   556   ...   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