A really useful feature of VB.Net is to be able to define a sub or
function with a variable array of parameters. It often seems unfair
that a language's own interal functions allow an unlimited number of
parameters, and yet your own must explicitly declare them. VB6
supported optional parameters which is still supported in .Net, but
this feature's much better.
Public Function Concat(ByVal ParamArray Args() As String) As String
Dim objSB As New Text.StringBuilder
For i As Integer = 0 To Args.GetUpperBound(0)
objSB.Append(Args(i))
Next
Return objSB.ToString
End Function
Console.WriteLine(Concat())
Console.WriteLine(Concat("a"))
Console.WriteLine(Concat("xyz", "123", "3453"))
Console.WriteLine(Concat("a", "b", "c", "d", "e", "f", "g"))
Public Function Concat(ByVal ParamArray Args() As String) As String
Dim objSB As New Text.StringBuilder
For i As Integer = 0 To Args.GetUpperBound(0)
objSB.Append(Args(i))
Next
Return objSB.ToString
End Function
Console.WriteLine(Concat())
Console.WriteLine(Concat("a"))
Console.WriteLine(Concat("xyz", "123", "3453"))
Console.WriteLine(Concat("a", "b", "c", "d", "e", "f", "g"))
202 comments,
VB.Net, Wednesday, December 8, 2004 13:24


