VB.NET中的类之间的调用

前端之家收集整理的这篇文章主要介绍了VB.NET中的类之间的调用前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

在用C#之间调用类时如下:

【C#】

class Class1
{

private string _strName;
public string StrName
{
get { return _strName; }
set { _strName = value; }
}
}

class Class2
{
public String GetClass1Property()
{
Class1 c1 = new Class1();
c1.StrName="A";
return c1.StrName;
}
}

但是在VB.NET中进行上如仿造练习是频频出错的。个人实验后正确代码如下(或许还有其他方式)

【VB.NET】

Public Class test1

Private _strNum As String
Public Property StrNum As String
Get
Return _strNum
End Get
Set(ByVal value As String)
_strNum = value
End Set
End Property

Property Orders As New List(Of String) From {"A","B","C"}
End Class

----------------------------------

Public Class test2

Public Sub ClassGet()
Dim t1 As New test1
t1.StrNum = "a"
End Sub

Public Function ClassGetFunction() As String
Dim t2 As New test1
t2.StrNum = "B"
Return t2.StrNum
End Function
End Class

个人理解也就是在类间调用时需要写道Sub或这Function中不能一开始就直接调用

猜你在找的VB相关文章