OK 할당이 나는 다음과 같은 코드를 시도했지만 나는 AllGreets.DynamicInvoke과 예외가내 vb.net 과정에이 과제가 있습니다. 뭐가 문제 야?
1) Write a program using various procedures to perform the operations listed below. Call these procedures using delegates. Make sure to document your program and have the program print descriptive text along with the numbers in b. and c. a) Print a text string in reverse word order. b) Print the number of characters in the string. c) Print number of words in the string.
그래서. 이 문제를 해결하려면 어떻게해야합니까?
나는 프로그래머가별로 없으며이 수업을 듣는 것이 내가 선택한 최고의 선택이 아니었지만 지금은 끝내야한다. 그것은 이미 지불 되었기 때문입니다.
Module Module1
Sub Main()
Dim part1 As GreetingDelegate
Dim part2 As GreetingDelegate
Dim part3 As GreetingDelegate
Dim part4 As GreetingDelegate
part1 = AddressOf greating
part2 = AddressOf greatingchar
part3 = AddressOf reverse
part4 = AddressOf number
Dim AllGreets As GreetingDelegate = _
[Delegate].Combine(part1, part2, part3, part4)
AllGreets.DynamicInvoke()
End Sub
Public Delegate Sub GreetingDelegate(ByVal MsgString As String)
' What the greating is
Public Sub greating()
Console.WriteLine("The greating is Hi how are you?")
System.Console.WriteLine("press enter")
Console.ReadLine()
End Sub
' Number of char in string
Public Sub greatingchar()
Dim thing As Long
thing = Len("Hi how are you?")
System.Console.WriteLine("There is")
System.Console.WriteLine(thing)
System.Console.WriteLine("characters in this greating")
System.Console.WriteLine("press enter")
Console.ReadLine()
End Sub
Public Sub reverse()
' string in reverse
Dim t As String
t = StrReverse$("Visual Basic")
System.Console.WriteLine(t)
System.Console.WriteLine("press enter")
System.Console.ReadLine()
End Sub
Public Sub number()
'number of word in string
Dim count As Long
Dim text As String
text = "Hi how are you?"
count = text.Split(" ").Length
System.Console.WriteLine(count)
System.Console.WriteLine("press enter")
System.Console.ReadLine()
End Sub
End Module
이 메서드는 대리자 선언과 일치해야합니다. greate()는 문자열 인수를 취하지 않습니다. 그리고 DynamicInvoke() 메서드에 문자열을 전달하는 것을 잊지 마십시오. –