如何从VB.NET中的其他类访问变量? [英] How can I access variables from other classes in VB.NET?
本文介绍了如何从VB.NET中的其他类访问变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是一个初级程序员,我需要知道如何访问和编辑另一个类的变量.这是我的一些示例代码
I'm a beginning programmer, and I need to know how to access and edit variables for another class. This is some example code I have
Public Class class1
Dim strName, strAge, strGender As String
Public Class class2
/ I need to edit the variables in this class. How do I do this?
推荐答案
您需要创建一个暴露变量的属性:
You need to make a property that exposes the variable:
Dim ThisClassVariable as String
Public Property ClassVariable as String
Get
Return ThisClassVariable
End Get
Set(ByVal Value As String)
ThisClassVariable = value
End Set
End Property
然后,当您创建名为"foo"的类的实例时,可以使用 foo.ClassVariable
Then when you create an instance of the class named "foo" you access the variable by using foo.ClassVariable
https://msdn.microsoft.com/en-us/library/e8ae41a4.aspx
这篇关于如何从VB.NET中的其他类访问变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文