我对编程有点新意,我在完成这项工作时遇到了麻烦。我应该使用委托运行此代码,但我在发生错误后遇到错误。我正在使用Vb.net。任何人都可以帮我解决这段代码中的问题吗?
Public Delegate Function D()
Dim Str As String = Console.ReadLine()
Sub Main()
Dim D1 As D
D1 = New D(AddressOf Fn1)
End Sub
Function Fn1()
System.Console.WriteLine("Please enter the string")
Dim revstr As String = StrReverse(Str)
Console.WriteLine("Reverse:")
Console.WriteLine(revstr)
Console.WriteLine("Amount of characters in the string:")
Dim Count As Integer = Str.Length
Console.WriteLine(Count)
Console.WriteLine("Amount of words in the string:")
Dim TempA() As String = Str.Split(" ")
Console.WriteLine(TempA.Length & " ")
Console.ReadKey()
End Function
感谢任何人的帮助!
答案 0 :(得分:3)
你的功能Fn1不会返回任何内容。
按定义的函数返回一些东西。如果您想要一个不返回任何内容的方法,您应该声明它Sub
而不是Function
您的函数还应该声明数据类型正在返回:
Public Function Concat(s1 As String, s2 As String) As String
return s1 & s2
End Function