简体   繁体   中英

How to write Lambda properties in VB.Net

I have not coded in VB.NET for about 10 years and now I'm having trouble finding the equivalent syntax for this:

public virtual string SomeProperty => "SomeValue"; 

VB does not have the expression-bodied members. You have to do it the traditional way:

Public Overridable ReadOnly Property SomeProperty() As String
    Get
        Return "SomeValue"
    End Get
End Property

It isn't identical in the general case, but for this specific case, you could use an implicitly-defined property with initialization:

Public Overridable ReadOnly Property SomeProperty As String = "SomeValue"

This is less general than the C# above in that it only works for an initial value, whereas I believe the C# can define a function which would be evaluated each time the property value is retrieved. (In this case, the C# function just returns a string constant, so it's equivalent to initializing the property with that constant value.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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