DispIdAttribute Class


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

public ref class DispIdAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Event | System.AttributeTargets.Field | System.AttributeTargets.Method | System.AttributeTargets.Property, Inherited=false)]
public sealed class DispIdAttribute : Attribute
type DispIdAttribute = class
    inherit Attribute
Public NotInheritable Class DispIdAttribute
Inherits Attribute


The following example demonstrates how explicit DISPIDs can be assigned to members of a class.

using namespace System::Runtime::InteropServices;
public ref class MyClass

   void MyMethod(){}

   int MyOtherMethod()
      return 0;

   bool MyField;

using System.Runtime.InteropServices;

public class MyClass
   public MyClass() {}

   public void MyMethod() {}
   public int MyOtherMethod() {
      return 0;
   public bool MyField;
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


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.

See DISPID Constants for a list of commonly used DISPID values.



Initializes a new instance of the DispIdAttribute class with the specified DISPID.



When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Gets the DISPID for the member.



Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)

Returns the hash code for this instance.

(Inherited from Attribute)

Gets the Type of the current instance.

(Inherited from Object)

When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)

When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)

Creates a shallow copy of the current Object.

(Inherited from Object)

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)

Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Applies to