O'Reilly logo

Programming Visual Basic .NET by Dave Grundgeiger

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

Attributes

An attribute is a program element that modifies some declaration. Here is a simple example:

<SomeAttribute(  )> Public Class SomeClass
   ' ...
End Class

This example shows a fictitious SomeAttribute attribute that applies to a class declaration. Attributes appear within angle brackets (<>) and are following by parentheses (( )), which may contain a list of arguments. To apply multiple attributes to a single declaration, separate them with commas within a single set of angle brackets, like this:

<SomeAttribute(), SomeOtherAttribute(  )> Public Class SomeClass
   ' ...
End Class

Attributes can be placed on the following kinds of declarations:

Types

This includes classes, delegates, enumerations, events, interfaces, Visual Basic .NET standard modules, and structures.

The attribute is placed at the beginning of the first line of the type declaration:

<SomeAttribute(  )> Public Class SomeClass
   ' ...
End Class
Constructors

The attribute is placed at the beginning of the first line of the constructor declaration:

<SomeAttribute()> Public Sub New(  )
   ' ...
End Sub
Fields

The attribute is placed at the beginning of the field declaration:

<SomeAttribute(  )> Public SomeField As Integer
Methods

The attribute is placed at the beginning of the first line of the method declaration:

<SomeAttribute()> Public Sub SomeMethod(  )
' ...
End Sub
Parameters

The attribute is placed immediately prior to the parameter declaration. Each parameter can have its own attributes:

Public Sub SomeMethod(<SomeAttribute( )> ...

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