简体   繁体   English

VB.NET MVC ViewModel获取和设置

[英]VB.NET MVC ViewModel Get and Set

If a model has declared a string in C# as such: 如果模型在C#中这样声明了一个字符串:

public string Message { get; set; }

And I use the C# to VB.net Telerik Code Converter , my string now becomes: 我使用C#到VB.net Telerik代码转换器 ,现在我的字符串变为:

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

That is too many lines of code I would like to avoid for declaring a string. 我想避免声明字符串太多代码行。 If I have 50 strings in a viewmodel, it becomes to bulky. 如果我在视图模型中有50个字符串,它将变得笨重。

This works in VB.net: 这在VB.net中有效:

 Public Property Message() As String

Does declaring the string this way handle the get; 是否以这种方式声明字符串来处理get; set; 组; by default? 默认? Are there any pros or cons for ether VB.net examples I provided? 我提供的以太VB.net示例是否有优点或缺点?

The shorter form is called auto-implemented properties , and basically works the same way as the longer method. 较短的形式称为auto-implemented properties ,基本上与较长的方法相同。 The compiler does the extra work behind the scenes. 编译器在后台进行了额外的工作。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM