C# 0 The Complete Reference



Download 4,07 Mb.
Pdf ko'rish
bet766/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   762   763   764   765   766   767   768   769   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt


partial class XY {

  public int Y { get; set; }

}

The following file demonstrates the use of 



XY

:

// Demonstrate partial class definitions.



using System;

www.freepdf-books.com




604

 

P a r t   I :  



T h e   C #   L a n g u a g e

class Test {

  static void Main() {

    XY xy = new XY(1, 2);

    Console.WriteLine(xy.X + "," + xy.Y);

  }


}

To use 


XY

, all files must be included in the compile. For example, assuming the 



XY

 files 


are called 

xy1.cs

,

 xy2.cs

, and 

xy3.cs

, and that the 



Test

 class is contained in a file called 



test.cs

,

then to compile 



Test

, use the following command line:

csc test.cs xy1.cs xy2.cs xy3.cs

One last point: It is legal to have partial generic classes. However, the type parameters 

of each partial declaration must match the other parts.

Partial Methods

As the preceding section described, you can use 



partial

 to create a partial type. Beginning 

with C# 3.0, there is a second use of 

partial

 that lets you create a 



partial method

 within a 

partial type. A partial method has its declaration in one part and its implementation in 

another part. Thus, in a partial class or structure, 



partial

 can be used to allow the declaration 

of a method to be separate from its implementation.

The key aspect of a partial method is that the implementation is not required! When the 

partial method is not implemented by another part of the class or structure, then all calls to 

the partial method are silently ignored. This makes it possible for a class to specify, but not 

require, optional functionality. If that functionality is not implemented, then it is simply 

ignored.


Here is an expanded version of the preceding program that creates a partial method 

called


Show( )

. It is called by another method called 



ShowXY( )

. (For convenience, all pieces 

of the partial class 

XY

 are shown in one file, but they could have been organized into 

separate files, as illustrated in the preceding section.)

// Demonstrate a partial method.

using System;

partial class XY {

  public XY(int a, int b) {

    X = a;

    Y = b;

  }


  // Declare a partial method.

  partial void Show();

}

partial class XY {



  public int X { get; set; }

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   762   763   764   765   766   767   768   769   ...   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