我有一个像这样定义的VB.Net结构: -
Public Structure MyStructure
Public Property MyProperty () As String
Get
Return "" ' Return something
End Get
Set
' Do something
End Set
End Property
Public Property MyProperty (Byval my_parameter As String) As String
Get
Return "" ' Return something
End Get
Set
' Do something
End Set
End Property
End Structure
我试图从一些C#代码调用这些属性。我可以使用如下参数调用重载: -
MyStructure the_structure = New MyStructure ();
the_structure.set_MyProperty ("Hello", "World");
但尝试使用这样的无参数版本: -
the_structure.set_MyProperty ("Hello");
导致编译错误: -
No overload for method 'set_MyProperty' takes 1 arguments
get: -
会出现类似的结果string string1 = the_structure.get_MyProperty("Hello"); // Fine
string string2 = the_structure.get_MyProperty(); // Compilation error
有谁知道我应该如何调用无参数属性?
答案 0 :(得分:1)
正常的方式应该有效。
string string2 = the_structure.MyProperty;