什么是C#中的DispId注释?

前端之家收集整理的这篇文章主要介绍了什么是C#中的DispId注释?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
例如
public interface IWMPSettings

        [DispId(101)]
        bool autoStart { get; set; }
        [DispId(102)]
        int balance { get; set; }

它是有用的还是只是自动生成编译器?

解决方法

总之,是的,它是有用的,但只有COM发送:

The DispIdAttribute(来自MSDN):

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

This attribute contains the DISPID for the method,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.

猜你在找的C#相关文章