-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: Swami_SRS
Message 2 in Discussion
Hi,
There is an simple and direct method to implement your requirement. If you had not
heard about it, its called the ParamArray.
"ParamArray is a special access modifier to a parameter of any method, which if
provided, allows you to pass any arbitrary number of arguments to the method."
Sample Code:
Method that utilises the paramarray for addition:
Function AddAll(ByVal ParamArray list() As Int32)
Dim entry As Int32
Dim sum = 0
For Each entry In list
sum = sum + entry
Next
Return sum
End Function
In the above function the input list is an array of integers. You can loop through the
list to get the sum. All as usual till now. Now lets look at the method to invoke the
function:
Method Invocation:
Sub DemoParamArray()
Dim sum As Int32
sum = AddAll(2, 4, 5, 7, 8, 3, 5, 6, 7, 8, 99, 32)
WriteLine(sum)
End Sub
As you see in the above method DemoParamArray, any number of arguments can be passed
to the function AddAll in a manner identical to any other method invocation. You need
not create an array to pass the same. There are some limitations for a parameter to
be given the modifier paramArray. They are: 1. There can be only one parameter
declared as paramArray in method definition. 2. The paramArray-ed parameter should be
the last parameter in the method defn. 3. The paramArray-ed parameter can obly be
passed by-val. Hope this suits you,
Swami.
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]