This documentation is archived and is not being maintained.

DispIdAttribute Class

Specifies the COM dispatch identifier (DISPID) of a method, field, or property.

For a list of all members of this type, see DispIdAttribute Members.


[Visual Basic]
<AttributeUsage(AttributeTargets.Method Or _
   AttributeTargets.Property Or AttributeTargets.Field Or _
NotInheritable Public Class DispIdAttribute
   Inherits Attribute
[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property
   | AttributeTargets.Field | AttributeTargets.Event)]
public sealed class DispIdAttribute : Attribute
[AttributeUsage(AttributeTargets::Method |
   AttributeTargets::Property | AttributeTargets::Field |
public __gc __sealed class DispIdAttribute : public Attribute
   AttributeUsage(AttributeTargets.Method | AttributeTargets.Property
   | AttributeTargets.Field | AttributeTargets.Event)
class DispIdAttribute extends Attribute

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


You can apply this attribute to methods, fields, or properties.

This attribute contains the DISPID for the method, field, or property it describes. Unique DISPIDs are typically assigned by the common language runtime, but you can use this attribute to assign a specific DISPID to a method. When importing a type library, this attribute is applied to all methods with assigned DISPIDs. This ensures that any managed implementation of the same method retains the same DISPID if exposed to COM.


[Visual Basic, C#, C++] The following example demonstrates how explicit DISPIDs can be assigned to members of a class.

[Visual Basic] 
Imports System.Runtime.InteropServices

Class SampleClass
    Public Sub New()
        'Insert code here.
    End Sub
    <DispIdAttribute(8)> _ 
    Public Sub MyMethod()
        'Insert code here.
    End Sub    
    Public Function MyOtherMethod() As Integer
        'Insert code here.
        Return 0
    End Function
    <DispId(9)> _
    Public MyField As Boolean
End Class

using System.Runtime.InteropServices;

public class MyClass
   public MyClass() {}

   public void MyMethod() {}
   public int MyOtherMethod() {
      return 0;
   public bool MyField;

using namespace System::Runtime::InteropServices;

public __gc class MyClass
   MyClass() {}

   void MyMethod() {}
   int MyOtherMethod() {
      return 0;
   bool MyField;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Runtime.InteropServices

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

Assembly: Mscorlib (in Mscorlib.dll)

See Also

DispIdAttribute Members | System.Runtime.InteropServices Namespace