【问题标题】:Can an Interface contain an ENum?一个接口可以包含一个 Enum 吗?
【发布时间】:2011-01-10 00:55:21
【问题描述】:

接口可以包含枚举吗?

我正在使用 asp.net 2.0。当我在下面的界面中添加一个枚举时,突然我的代码开始出现问题。其中,LookUpType 是一个枚举。

Public Interface ILookup
    Property ID() As Int32
    Property Text() As String
    Property Description() As String
    Property Status() As Status
    Property OrderID() As Int32
    ReadOnly Property LookUpType() As LookUpType
End Interface

【问题讨论】:

    标签: .net asp.net vb.net interface


    【解决方案1】:

    你的问题有点模棱两可,听起来你可能会问以下任何一个问题

    接口可以返回枚举类型吗?

    是的。枚举在任何方面都不是特殊的,可以防止它们成为接口上的返回类型

    接口可以包含枚举定义吗?

    是的,这在 VB.Net 中是完全合法的。然而,它在 C# 中是不合法的

    Interface IFoo
        Enum E1
            V1
        End Enum
        Function SomeMethod() As E1
    End Interface
    

    【讨论】:

    • 当我看到这个时,我看到的只是大胆的问题。我的眼睛! :D
    • 我可以证明 C# 与 VB.NET 之间这种差异的真实性,但是,我不明白为什么会这样。 2019 年 10 月仍然如此
    猜你喜欢
    • 2021-11-20
    • 2011-03-17
    • 1970-01-01
    • 2018-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-31
    • 2013-11-02
    相关资源
    最近更新 更多