1. Home
  2. Computing & Technology
  3. Visual Basic
Attributes in VB .NET
Page 2 - The Two Types of Attributes
 More of this Feature
• 1 - Attributes in VB .NET
• 3 - An Example: The Predefined VBFixedString Attribute
• 4 - An Example: Custom Attributes
 
 Join the Discussion
Is this the kind of article that helps you?
Let us know!
 

Any application can use the added information provided by an attribute. In general, there are two types of attributes in VB .NET: predefined and custom. A predefined attribute is used by the .NET Framework itself. You can use the same techniques in your own applications with custom attributes.

Here's just a few of the predefined attributes taken from Microsoft's documentation. Notice that a recommended coding practice is to create an attribute name by dropping the trailing string "Attribute".

COMClassAttribute Class
Indicates to the compiler that the class should be exposed as a COM object. Specific to Visual Basic .NET.

VBFixedStringAttribute Class
Specifies the size of a fixed-length string in a structure for use with file input and output functions. Specific to Visual Basic .NET.

VBFixedArrayAttribute Class
Specifies the size of a fixed array in a structure for use with file input and output functions. Specific to Visual Basic .NET.

WebMethodAttribute Class
Makes a method callable using the SOAP protocol. Used in XML Web services. SerializableAttribute Class Indicates that a class can be serialized.

MarshalAsAttribute Class
Determines how a parameter should be marshaled between the managed code of Visual Basic .NET and unmanaged code such as a Windows API. Used by the common language runtime.

AttributeUsageAttribute Class
Specifies how an attribute can be used. DllImportAttribute Class Indicates that the attributed method is implemented as an export from an unmanaged DLL.

The three attributes that are specific to Visual Basic .NET are: COMClassAttribute, VBFixedStringAttribute, and VBFixedArrayAttribute.

Next page > An Example: The Predefined VBFixedString Attribute > Page 1, 2, 3, 4

Explore Visual Basic
By Category
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

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

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

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

All rights reserved.