Object Array

  • Thread starter Thread starter Jonathan Lurie
  • Start date Start date
J

Jonathan Lurie

Is it a bad practice using a object array.

Example
Sub DoSomething(ByVal arg() As Object)
.....
End Sub

DoSomething(New Object() {"A", "B"})

If yes, then how do we create a function when parameter could be anything.

John
 
Generally it is bad practice since you loose type checking.
However, if the data can truly be of _any_ type then you have
no choice. If you have a limited set of types though, I suggest
using overloads instead. For example:

Public Sub Overloads DoSomething(ByVal arg() As Integer)
....
End Sub

Public Sub Overloads DoSomething(ByVal arg() As String)
....
End Sub

/claes
 
Back
Top