【问题标题】:VB.NET MVC ViewModel Get and SetVB.NET MVC ViewModel 获取和设置
【发布时间】:2017-08-17 22:18:49
【问题描述】:

如果模型在 C# 中声明了这样的字符串:

public string Message { get; set; }

而我用C#转VB.netTelerik Code Converter,我的字符串现在变成了:

Public Property Message() As String
    Get
        Return m_Message
    End Get
    Set
        m_Message = Value
    End Set
End Property
Private m_Message As String

为了声明一个字符串,我想避免的代码行太多。如果我在视图模型中有 50 个字符串,它就会变得庞大。

这适用于 VB.net:

 Public Property Message() As String

以这种方式声明字符串是否会处理get;放;默认?我提供的 ether VB.net 示例有什么优点或缺点吗?

【问题讨论】:

  • 查看stackoverflow.com/questions/6080774/… - 如果我需要做一些不规范的事情,例如向 getter 或 setter 添加参数,我将使用更详细的方式来定义属性,甚至那么我通常会为它单独制作一个方法。

标签: asp.net-mvc vb.net viewmodel c#-to-vb.net


【解决方案1】:

较短的形式称为auto-implemented properties,其工作方式与较长的方法基本相同。编译器在幕后做额外的工作。

https://msdn.microsoft.com/en-us/library/dd293589.aspx

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多