VB.Net/Language Basics/Function — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:40, 26 мая 2010

Define and Call Function

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
       Console.WriteLine("In Main! Calling SomeMethod( )...")
       SomeMethod( )
       Console.WriteLine("Back in Main( ).")
    End Sub
    Shared Sub SomeMethod( )
       Console.WriteLine("Hi")
    End Sub "SomeMethod
End Class


Define and use Function

Imports System
Public Class MainClass
    Shared Sub Main(ByVal args As String())
      PrintPay(40, 10.5)
      PrintPay(38, 21.75)
      PrintPay(20, 13)
      PrintPay(50, 14)
    End Sub
   Shared Sub PrintPay(ByVal hours As Double, ByVal wage As Decimal)
      Console.WriteLine("The payment is {0:C}", hours * wage)
   End Sub 
End Class


Define and Use Function: Shared Function

Imports System
Public Class MainClass
    
    Shared Sub Main(ByVal args As String())
        Dim area As Double
        area = CalculateAreaFromRadius(100)
    
        Console.WriteLine("Area: " & area)
    End Sub
    
    Shared Function CalculateAreaFromRadius(ByVal radius As Double) As Double
        " square the radius...
        Dim radiusSquared As Double
        radiusSquared = radius * radius
        " multiply it by pi...
        Dim result As Double
        result = radiusSquared * Math.PI
        " return the result...
        Return result
    End Function
End Class