是否有可能隐藏字段(或只是从操作自动完成/隐藏)自己的类中? [英] Is it possible to hide a field (or just manipulate/hide from autocomplete) within its own class?
问题描述
我有分量的通常搭配一个(相当)复杂的文件。
I have a (quite) complicated file with the usual mix of components.
我有一个字段(名为 keyloaded
)和链接的属性(被称为 Keyloaded
)。
I have a field (called keyloaded
) and a linked property (called Keyloaded
).
虽然类中的工作,我不小心直接操作领域,而不是财产。
Whilst working within the class, I accidentally directly manipulated the field instead of the property.
这最有可能是因为我还是贵了点新的这一切(我现在的三重检查!),但是,这已经是一个私人领域,并与工作类以外的伟大工程。有没有只是简单的东西我能做到这一点从自动完成删除它?
It most likely is because I am still quite a bit new to all of this (I triple check now!), however, this is already a private field and outside of working with the class works great. Is there just something simple I can do that will remove it from Autocomplete?
如果不是,什么是类似情况的最佳实践?
And if not, what are the best practices for a similar situation?
虽然写这个问题时,我突然在我的书还记得,他们说,大约下划线......这仅仅是最好的解决办法 - 把它的视线
Whilst writing this question, I suddenly remembered in my book, they said about underscores... Is this just the best solution - to put it out of sight?
推荐答案
像布赖恩和KBoek提到你可以以下划线开头的领域。但如果你真的想隐藏的方法/字段/属性可以设置属性,如图所示。这将防止在intellesense被所示的方法/字段/属性。然而,该部件将仍然访问。
Like Brian and KBoek mentioned you can just start your fields with an underscore. But if you really want to hide a method/field/property you can set the attribute as shown. This will prevent the method/field/property from being shown in intellesense. However, The member will still be accessible.
<System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)> _
Public Property HiddenProperty()
Get
return _hiddenProperty
End Get
Set (value as object)
_hiddenProperty = value
End Set
End Sub
这篇关于是否有可能隐藏字段(或只是从操作自动完成/隐藏)自己的类中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!