简体   繁体   English

VB.net中的myObject.MyField和myObject.MyField()有什么区别?

[英]What's the difference between myObject.MyField and myObject.MyField() in VB.net?

I stumbled upon this issue: 我偶然发现了这个问题:

myObject 's class has a public field MyField which type is Decimal? myObject的类具有一个公共字段MyField ,哪种类型为Decimal?

I accidentally access the field as if it were a property with this code: 我不小心访问该字段,就好像它是具有以下代码的属性:

myObject.MyField()

instead of 代替

myObject.MyField

And I got the following error from the compiler: Structure 'Decimal?' cannot be indexed because it has no default property 而且我从编译器中收到以下错误: Structure 'Decimal?' cannot be indexed because it has no default property Structure 'Decimal?' cannot be indexed because it has no default property

Documentation on this error on MSND is very short and I just don't understand what it means. 有关此MSND错误的文档非常简短,我只是不明白这意味着什么。

Q: What's the meaning of myObject.MyField() if it has one, and why can't I use it on my field if so? 问:如果myObject.MyField()有一个,它是什么意思,为什么我不能在我的字段上使用它?

Note: my problem is now solved but I would like to understand... 注意:我的问题现在已经解决,但我想了解...

You access elements of an array using () in VB.NET. 您可以在VB.NET中使用()访问数组的元素。 The error message is telling you Structure 'Decimal?' cannot be indexed 错误消息告诉您Structure 'Decimal?' cannot be indexed Structure 'Decimal?' cannot be indexed because it can't. Structure 'Decimal?' cannot be indexed因为它无法建立Structure 'Decimal?' cannot be indexed

In that context it is the index operator, just like [] in C#. 在这种情况下,它就是索引运算符,就像C#中的[]

To be more precise, in VB.NET it is called "default property" and in C# it is called "indexer". 更准确地说,在VB.NET中将其称为“默认属性”,在C#中将其称为“索引器”。

See here for even more details. 有关更多详细信息,请参见此处

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

相关问题 vb.net中参数化属性和函数有什么区别? - What is the difference between a parameterized property and function in vb.net? 当我给MyObject obj = new MyObject()时发生了什么 - What is happening when I give MyObject obj = new MyObject() C# static class 和 ZBD5C8A1AFE53C80BA44F60C9AFC6 模块之间有什么区别(如果有) - What, if any, difference is there between a C# static class and a VB.NET Module vb.NET中的此正则表达式有什么问题? - What's wrong with this regex in vb.NET? VB.NET中的公共变量和公共属性有什么区别? (代码分析VS2010,CA1051:Microsoft.Design) - What's the difference between Public variable and Public Property in VB.NET? (Code Analysis VS2010, CA1051 : Microsoft.Design) C#和VB.NET中的转换之间的区别 - Difference between casting in C# and VB.NET C#和VB.NET控制台会话之间的区别 - Difference between C# and VB.NET console session VB.Net与C#“As New WebControl”的区别 - Difference between VB.Net and C# “As New WebControl” VB.NET中SystemEvents的Handles声明和AddHandler之间的区别 - Difference between Handles declaration and AddHandler for SystemEvents in VB.NET 阴影(VB.NET)和新(C#)之间的区别 - Difference between Shadows (VB.NET) and New (C#)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM