首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >System.Reflection.TargetParameterCountException

System.Reflection.TargetParameterCountException
EN

Stack Overflow用户
提问于 2014-08-09 19:45:57
回答 1查看 247关注 0票数 0

我必须为这个类编写一个程序,让我调用一个多播代表,向后写一个字符串,计数字符和单词。我已经解决了所有的问题,但是当我运行它时,我得到: System.Reflection.TargetParameterCountException

我昨天才了解到代表们的情况,所以我可能错过了一些明显的事情。

代码语言:javascript
运行
复制
Private Delegate Sub Words(ByVal input As String)
    Sub Main()
    Console.Title = "Fun with words"
    Console.WriteLine("Type some words below.")
    Dim Input As String = Console.ReadLine()
    Dim Display As [Delegate]
    Dim Backwards As Words
    Dim Length As Words
    Dim Wordcount As Words
    Backwards = New Words(AddressOf BackwardsFunc)
    Length = New Words(AddressOf LengthFunc)
    Wordcount = New Words(AddressOf WordcountFunc)
    Display = MulticastDelegate.Combine(Backwards, Length, Wordcount)
    Display.DynamicInvoke()

    Console.ReadKey() 'end
End Sub
Sub BackwardsFunc(ByVal Input As String)
    ' Backwards
    Console.Clear()
    Console.ForegroundColor = ConsoleColor.Cyan
    Console.WriteLine(Input)
    Console.ResetColor()
    Console.WriteLine("Backwards:")
    Dim Array() As Char = Input.ToCharArray
    Dim Stack As New Stack()
    For Each element As Char In Array
        Stack.Push(element)
    Next
    For Each element As Char In Stack
        Console.WriteLine(element)
    Next
End Sub
Sub LengthFunc(ByVal Input As String)
    Console.WriteLine()
    Console.WriteLine("Length: " & Input.Length)
End Sub
Sub WordcountFunc(ByVal Input As String)
    Dim Items As String() = Input.Split(New Char() {" "c})
    Console.WriteLine()
    Console.WriteLine("Words: " & Items.Length)
End Sub
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-09 20:28:50

您的委托Words需要一个参数,但在调用委托时不提供参数。

在调用MulticastDelegate时,还提供委托必须使用的参数,如下所示:

代码语言:javascript
运行
复制
Display.DynamicInvoke(Input)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25222379

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档