1. Technology

Attributes in VB.NET - Part One

Store and use information in the assembly metadata.

By

Typing on Keyboard
blackred/E+/Getty Images
Updated July 02, 2014

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's a feature that you'll see more frequently as you learn advanced programming techniques.

Just to make sure that you understand what this article is about, let's look what the article is not about first to get it out of the way. You might have a background in XML or HTML. In those languages, an attribute is a "modifier of an element". For example, consider this HTML anchor tag:


<a href="http://visualbasic.about.com/index.htm">About Visual Basic</a>

href is an HTML attribute of the anchor tag element named a.

Although the concept is similar, this article is not about XML or HTML attributes. Instead, this article explains how to use attributes in VB.NET code to "declare" information or processing that is saved with the code definition. You might see other articles that say attributes add "a declarative dimension to designing and writing software". I'll explain just what that means.

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. This one is short on detail but I'll start supplying that detail on the next page where we cover the two types of attributes in VB.NET: Predefined Attributes and Custom Attributes.

  1. About.com
  2. Technology
  3. Visual Basic
  4. Using VB.NET
  5. Attributes in Visual Basic .NET

©2014 About.com. All rights reserved.