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 ...

Get From Java to C#: A Developer's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.