VB.NET中的类之间的调用

来源:互联网 发布:淘宝的iphone7便宜 编辑:程序博客网 时间:2024/05/16 18:35

在用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中不能一开始就直接调用的

 

原创粉丝点击