Website Design United States, Website Design California, Website Designing United States, Website Designing California

Using ParamArray - Visual Basic .NET

Here is a simple example of how to use a ParamArray in VB.Net. The concenpt is the same for C#.

Module ParamTest

Public Sub Main()
Dim Values() As Int32 = {1, 2, 3, 4, 5, 6, 7, 8, 9}
Dim Avg As Double

'Here is our first example. Pass in the integer array.
'The AvgOfNumbers() function will use that array and compute
'the average of the numbers.
Avg = AvgOfNumbers(Values)
Console.WriteLine("Avg of Integer Array: " & Avg)

'Here is our second example. Pass in an unknown number of integers
'The AvgOfNumbers() function will use those numbers and compute
'the average of the numbers.
Avg = AvgOfNumbers(1, 2, 3, 4, 5, 6, 7, 8, 9)
Console.WriteLine("Avg of Parameter Array: " & Avg)
End Sub

Private Function AvgOfNumbers(ByVal ParamArray Numbers() As Int32) As Double
Dim i As Int32
Dim Total As Int32

'Cycle through the values and total them
For i = 0 To Numbers.GetUpperBound(0)
Total += Numbers(i)
Next

'Return the Total of the numbers divided by the Quantity of values
Return (Total / Numbers.GetUpperBound(0))
End Function

End Module

-----------------------------------------------------------


WEB DESIGN INDIA
42 B Malviya Nagar , New Delhi-110017

Skype: manmeetsi
Email: support.webdesignindia@gmail.com
Tel: 91-011-40502005, 9810067295

 















 


© 2008-2009 dotnet4all.com