C# 0 The Complete Reference


extern method AbsMax( )



Download 4,07 Mb.
Pdf ko'rish
bet776/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   772   773   774   775   776   777   778   779   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

extern

method


AbsMax( )

. In this case, the file is 



ExtMeth.dll

, which is the file DLL created when 

the C file was compiled. When the program is run, the value 20 is displayed, as expected.

Declaring an extern Assembly Alias

A second form of 



extern

 (which was added by C# 2.0) provides an alias for an external 

assembly. It is used in cases in which a program includes two separate assemblies that both 

contain the same name. For example, if an assembly called 



test1

 contains a class called 



MyClass

 and 


test2

 also contains a class called 



MyClass

, then a conflict will arise if both 

classes need to be used within the same program.

To solve this problem, you must create an alias for each assembly. This is a two-step 

process. First, you must specify the aliases using the 

/r

 compiler option. For example:

/r:Asm1=test1

/r:Asm2=test2

Second, you must specify 

extern

 statements that refer to these aliases. Here is the form of 



extern

 that creates an assembly alias:

extern alias 

assembly-name

;

Continuing the example, these lines must appear in your program:



extern alias Asm1;

extern alias Asm2;

Now, either version of 

MyClass

 can be accessed by qualifying it with its alias.

Here is a complete example that demonstrates an 

extern

 alias. It contains three files. The 

first is shown here. It should be put in a file called 

test1.cs

.

using System;



namespace MyNS {

  public class MyClass {

    public MyClass() {

      Console.WriteLine("Constructing from MyClass1.dll.");

    }

  }


}

The second file is called 



test2.cs

. It is shown here:

using System;

namespace MyNS {

  public class MyClass {

    public MyClass() {

      Console.WriteLine("Constructing from MyClass2.dll.");

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   772   773   774   775   776   777   778   779   ...   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