C# 0 The Complete Reference


Supplement  is a public field of  RemarkAttribute



Download 4,07 Mb.
Pdf ko'rish
bet615/1096
Sana23.01.2022
Hajmi4,07 Mb.
#402171
1   ...   611   612   613   614   615   616   617   618   ...   1096
Bog'liq
C-Sharp 3 The Complete Reference Herbert Schildt

Supplement

 is a public field of 



RemarkAttribute

, it can be used as a named parameter, 

as shown here:

[RemarkAttribute("This class uses an attribute.",

        Supplement = "This is additional info.")]

class UseAttrib {

  // ...

}

Pay close attention to the way 



RemarkAttribute

’s constructor is called. First, the 

positional argument is specified as it was before. Next is a comma, followed by the named 

parameter, 



Supplement

, which is assigned a value. Finally, the closing 



)

 ends the call to the 

constructor. Thus, the named parameter is initialized within the call to the constructor. This 

syntax can be generalized. Position parameters must be specified in the order in which they 

appear. Named parameters are specified by assigning values to their name.

Here is a program that demonstrates the 



Supplement

 field:


// Use a named attribute parameter.

using System;

using System.Reflection;

[AttributeUsage(AttributeTargets.All)]

public class RemarkAttribute : Attribute {

  string pri_remark; // underlies Remark property

  public string Supplement; // this is a named parameter

  public RemarkAttribute(string comment) {

    pri_remark = comment;

    Supplement = "None";

  }

  public string Remark {



    get {

      return pri_remark;

    }

  }


}

[RemarkAttribute("This class uses an attribute.",

                 Supplement = "This is additional info.")]

class UseAttrib {

  // ...

}

class NamedParamDemo {



  static void Main() {

    Type t = typeof(UseAttrib);

    Console.Write("Attributes in " + t.Name + ": ");

www.freepdf-books.com




Download 4,07 Mb.

Do'stlaringiz bilan baham:
1   ...   611   612   613   614   615   616   617   618   ...   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