函数不会在所有代码路径Vb.net上返回值 [英] Function doesn't return a value on all code paths Vb.net
本文介绍了函数不会在所有代码路径Vb.net上返回值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我对编程有些陌生,但在进行这项工作时遇到了麻烦。我应该使用委托来运行此代码,但遇到一个又一个错误。我正在使用Vb.net。有人可以帮我解决这段代码中的问题吗?
I'm somewhat new to programming and I am having trouble just making this work. I'm supposed to run this code using a delegate but I've run into error after error. I'm using Vb.net. Could anyone help me solve the issues in this code?
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
感谢
推荐答案
您的函数Fn1不返回任何内容。
Your Function Fn1 doesn't return anything.
函数按定义返回某些内容。如果要使用不返回任何内容的方法,则应将其声明为 Sub
而不是 Function
Functions by definition return something. If you want a method that doesn't return anything you should declare it Sub
instead of Function
您的函数还应该声明数据类型正在返回:
Your function should also declare the data type is is returning:
Public Function Concat(s1 As String, s2 As String) As String
return s1 & s2
End Function
这篇关于函数不会在所有代码路径Vb.net上返回值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文