【问题标题】:VB.NET Equivalent of this code此代码的 VB.NET 等效项
【发布时间】:2011-02-26 13:53:34
【问题描述】:

这段代码的 VB.NET 等价物是什么..

public virtual ICollection<Comment> Comments { get; set; }

【问题讨论】:

标签: c# vb.net c#-to-vb.net


【解决方案1】:

VB.NET(版本 10)与 C# 一样具有自动属性。等效语法如下:

Public Overridable Property Comments() As ICollection(Of Comment)

自动转换器往往会产生比必要的更冗长的语法。您可以根据需要扩展它,但除非您使用的是旧版本的编译器,否则这不是绝对必要的:

Private m_Comments As ICollection(Of Comment)

Public Overridable Property Comments() As ICollection(Of Comment)
    Get
        Return m_Comments
    End Get
    Set(ByVal value As ICollection(Of Comment))
        m_Comments = value
    End Set
End Property

【讨论】:

    【解决方案2】:
    Public Overridable Property Comments() As ICollection(Of Comment)
    

    【讨论】:

      【解决方案3】:
       Public Overridable Property Comments() As ICollection(Of Comment)
           Get
          Return m_Comments
          End Get
           Set
          m_Comments = Value
          End Set
       End Property
       Private Overridable m_Comments As ICollection(Of Comment)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-20
        • 1970-01-01
        相关资源
        最近更新 更多