为什么我可以访问同一班级的任何私人课程? [英] Why can I access any private within same class?
本文介绍了为什么我可以访问同一班级的任何私人课程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Module Module1
Sub Main()
Dim oMyTest As New MyTest
oMyTest.CreateMyName("Call From OutSide, Why Can't I assign directly to MyName")
'oMyTest.MyName = ("Why Can’t I DO THIS")
End Sub
End Module
Public Class MyTest
Private MyName As String
Public Sub CreateMyName(ByVal sString As String)
MyName = sString
Console.WriteLine(MyName)
Dim oMyTest As New MyTest
' oMyTest.MyName = "Why does this work"
' why does this work
' if I initiate a the same class object inside the same class i can access all private fields, function, and methods.
Console.WriteLine(MyName)
Console.WriteLine("Inside Obect: " & oMyTest.MyName)
End Sub
End Class
推荐答案
这是一个很好的资料来源,解释了VB术语中所有可用的访问修饰符的区别: ^ ].
这将解释您所要求的所有内容,然后再进行一些解释.
欢呼!
This here is an excellent source that explains the differences of all available access modifiers in VB terminology: http://msdn.microsoft.com/en-us/library/76453kax(v=vs.80).aspx[^].
That will explain all you asked and then some.
Cheers!
之所以起作用,是因为同一类的所有其他成员都可以看到该类的私有成员.
确实,您需要阅读此 [
It works because Private members of a class are visible to all other members of the same class.
Really, you need to read up on this[^]. This is a very basic concept you''re missing and cannot afford to misunderstand.
这篇关于为什么我可以访问同一班级的任何私人课程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文