调用另一个类的方法 - vb.net

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31137215/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 19:15:09  来源:igfitidea点击:

Call a method of another class - vb.net

vb.netclassmethods

提问by daro

I have a method called methtod1 defined as:

我有一个名为 methtod1 的方法定义为:

Public Sub method1()
        For Each elem In Me.arrayElemWithLogkNull
            Console.WriteLine(elem)
        Next
End Sub

This method is in a class called XMLClass. So I have the Mainclass and, there, I want to call the method1 of XMLClass. How am I supposed to do that? I'm trying with this: XMLClass.method1(), but it's not working.

此方法位于名为XMLClass. 所以我有这个Main类,在那里,我想调用 XMLClass 的 method1。我该怎么做?我正在尝试这个:XMLClass.method1(),但它不起作用。

回答by Btc Sources

You need to initialize an object from this class to use it. Would be something like:

您需要从此类初始化一个对象才能使用它。会是这样的:

Dim myObject as XMLClass = new XMLClass()
myObject.method1()