サーチ…


前書き

この関数はsubと似ています。しかし、関数は値を返します。関数は、単一または複数のパラメータを受け入れることができます。

関数の定義

関数を定義するのは本当に簡単です。

Function GetAreaOfARectangle(ByVal Edge1 As Integer, ByVal Edge2 As Integer) As Integer
    Return Edge1 * Edge2
End Function

Dim Area As Integer = GetAreaOfARectangle(5, 8)
Console.Writeline(Area) 'Output: 40

関数の定義#2

Function Age(ByVal YourAge As Integer) As String   
    Select Case YourAge
        Case Is < 18
            Return("You are younger than 18! You are teen!")
        Case 18 to 64
            Return("You are older than 18 but younger than 65! You are adult!")
        Case Is >= 65
            Return("You are older than 65! You are old!")                
    End Select
End Function

Console.WriteLine(Age(48)) 'Output: You are older than 18 but younger than 65! You are adult!


Modified text is an extract of the original Stack Overflow Documentation
ライセンスを受けた CC BY-SA 3.0
所属していない Stack Overflow