Function returning a value Learn programming Visual Basic (




Function returning a value


Create a program whose Main must be like this:

public static void Main()
int x= 3;
int y = 5;
Console.WriteLine( Sum(x,y) );

"Sum" is a function that you must define and that will be called from inside Main. As you can see in the example, it must accept two integers as parameters, and it must return an integer number (the sum of those two numbers).


Imports System
Public Class exercise99
    Public Shared Function Sum(ByVal a As Integer, ByVal b As Integer) As Integer
        Dim result As Integer
        result = a + b
        Return result
    End Function

    Public Shared Sub Main()
        Dim x As Integer = 3
        Dim y As Integer = 5
        Console.WriteLine(Sum(x, y))
    End Sub
End Class

Juan A. Ripoll - Systems Tutorials and Programming Courses ©  All rights reserved.  Legal Conditions.