Function doesn't return a value on all code paths Vb.net

て烟熏妆下的殇ゞ 提交于 2019-12-20 06:04:20

问题


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

Thanks for any help anyone can give!


回答1:


Your Function Fn1 doesn't return anything.

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


来源:https://stackoverflow.com/questions/25508744/function-doesnt-return-a-value-on-all-code-paths-vb-net

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!