1. Home
  2. Computing & Technology
  3. Visual Basic
Attributes in VB.NET
It's new in VB .NET!
Attributes

Attribute is a word that has been overloaded. Overloading is not just an object oriented programming technique. It's also something that happens to ordinary words when you're trying to figure out how to use a sophisticated development environment like VB .NET! Depending on your previous experience, you might have run into attributes before. In VB .NET, it represents a new feature with really great potential. You'll see more and more of attributes as you learn advanced programming techniques.

Here's an introduction to how attributes are used in VB .NET.


If you have a background in XML or HTML, the word attribute is a modifier of an element. For example, in the HTML Anchor tag:

<A HREF="link path">link text</A>

HREF is an attribute of the element A.

Visual Studio uses XML attributes 'behind the scenes' in a lot of ways and it's important for people just learning VB .NET to avoid confusing them with the 'other' attributes. We took advantage of XML attributes when we demonstrated one way to use the less expensive VB .NET Learning Edition and still be able to compile class libraries. (Learn more about that in the article, A Better Way To Inherit?.)

But (just to confuse you?), Visual Studio includes a technique borrowed from C++ that is also identified by the term attributes. If you have programmed Microsoft's MTS or COM, you might have used this type of attribute before .NET arrived. Attributes were used a great deal in COM, but they had to be programmed using a language called IDL (Interface Definition Language) and were generally considered to be a more advanced technique. VB .NET brings the same idea into the mainstream and gives it both power and makes it a lot easier to use. For example, attributes were only keywords in COM programming. But in VB .NET, they have the advantages of being objects.

Here's the 'book' description of VB .NET attributes straight from Microsoft:

Attributes are keyword-like tags in which you can specify additional information about entities defined in Visual Basic .NET applications. Attributes, which are saved with an assembly's metadata, annotate programming elements such as types, fields, methods, and properties.

Another definition ... maybe a little easier to understand ... is that an attribute is simply a class that inherits from System.Attribute.
(Trust Microsoft to make things harder than they have to be!)

This is the type of attribute that will be introduced in this article.

Next page > The Two Types of Attributes > Page 1, 2, 3, 4

Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.