Calculates the power of a value, defaults to square : Function Parameter « Language Basics « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Date Time
8.Development
9.Event
10.File Directory
11.Generics
12.GUI
13.Internationalization I18N
14.Language Basics
15.LINQ
16.Network Remote
17.Reflection
18.Security
19.Thread
20.Windows Presentation Foundation
21.Windows System
22.XML
23.XML LINQ
VB.Net » Language Basics » Function Parameter 




Calculates the power of a value, defaults to square
Calculates the power of a value, defaults to square

Imports System

Public Class MainClass

    Shared Sub Main(ByVal args As String())
      Dim value As Integer

      ' call version of Power depending on power input
      value = Power(Convert.ToInt32(3), _
           Convert.ToInt32(10))

      Console.WriteLineConvert.ToString(value) )

    End Sub

   ' use iteration to calculate power
   Shared Function Power(ByVal base As Integer, _
      Optional ByVal exponent As Integer = 2As Integer

      Dim total As Integer = 1
      Dim As Integer

      For i = To exponent
         total *= base
      Next

      Return total
   End Function ' Power

End Class

           
       














Related examples in the same category
1.Use Array as Function ParameterUse Array as Function Parameter
2.Pass Array as ParametersPass Array as Parameters
3.Two Dimension Array: Pass into a FunctionTwo Dimension Array: Pass into a Function
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.