„Sznikák példakódok” változatai közötti eltérés
aNincs szerkesztési összefoglaló |
Attributes |
||
| 303. sor: | 303. sor: | ||
} | } | ||
{{Infobox | |||
| cím = Attribútumok használata | |||
| háttérszín = #C0ffee | |||
| keretszín = black | |||
| tartalom = | |||
Mutasson példát attribútumokra C# nyelven (saját attributee létrehozás, használat, lekérdezés) | |||
{{Infobox-táblázat| | |||
{{Infobox-táblázatsor|A kód nyelve|C#}} | |||
}} | |||
}} | |||
[AttributeUsage(AttributeTargets.All)] | |||
public class AuthorAttribute : System.Attribute | |||
{ | |||
public readonly string name; | |||
public HelpAttribute(string _name) | |||
{ | |||
name = _name; | |||
} | |||
public string Name | |||
{ | |||
get | |||
{ | |||
return name; | |||
} | |||
} | |||
} | |||
// Használata | |||
[Author("Béla Béla")] | |||
class JustASimpleClass | |||
{ | |||
// ... | |||
} | |||
// Lekérdezés | |||
foreach( object attribute is something.GetCustomAttributes(true)) | |||
{ | |||
Console.WriteLine(attribute); | |||
} | |||
[[Kategória:Infoalap]] | [[Kategória:Infoalap]] | ||