O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

27.1. First look at attributes

Let's look at a first example of attributes. In the code fragment below, each method is tagged with an Author attribute: [5]

[5] Another way to put it is that the three methods are the targets of the [Author] attribute.

 1:  // MyClass.cs
 2:  using System;
 3:
 4:  public class MyClass{
 5:
 6:    [Author("Mok","21 Dec 02")] 
						<-- 1
						<-- 2
 7:    public void DoSomething(){
 8:      // some code
 9:    }
10:
11:    [Author("Mindy","22 Dec 02")]
						<-- 2
12:    public void DoSomethingElse(){
13:      // some code
14:    }
15:
16:    [Author("Abigail","27 Nov 02")]
						<-- 2
17:    public void DoNothing(){
18:      // some code
19:    }
20:  }

(1)Parameters passed into the attribure instance

(2)Attribute specification

I use the term 'attribute specification' to describe the attribute ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required