vb.net - 返回类方法名称的数组

标签 vb.net

我有以下内容。如何查询类 myExample 并返回该类方法名称的数组?

Sub Main()
    Dim x As New myExample

    '<<would like to return an array of x's method names i.e. {"hello","world","foo","bar"}

    Console.WriteLine("press [enter] to exit")
    Console.Read()
End Sub

Class myExample

    Public Shared y As Integer

    Public Sub hello()
        y = 1
    End Sub
    Public Sub world()
        y = 2
    End Sub
    Public Sub foo()
        y = 3
    End Sub
    Public Sub bar()
        y = 4
    End Sub
End Class

最佳答案

所有方法(包括继承的):

Dim example As New myExample()
Dim t As Type = example.GetType()
Dim methods = t.GetMethods()
Dim allMethodNames() As String = methods.Select(Function(m) m.Name).ToArray()

Type.GetMethods

关于vb.net - 返回类方法名称的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14497181/

相关文章:

vb.net -> =无法正常工作

asp.net - 正好 6 个字符的正则表达式,第一个必须是字母

.net - String.Replace 不会替换所有匹配项

html - 未安装 excel 时运行 Excel 宏

c# - Infragistics UltraGrid 中复选框的检查更改会引发哪个事件?

VB.NET:如何在 xml 文档中引用通用类和方法

c# - .Net 数据结构 : ArrayList, List、HashTable、Dictionary、SortedList、SortedDictionary——速度、内存以及何时使用它们?

c# - 根据自签名证书的验证程序,远程证书无效

java - 在 VB.NET 应用程序的窗口中运行 JAR 应用程序 (Java)?

vb.net - vb.net sqlite从日期时间获取日期,该日期保存为dbtype.string