Roshawn said:
I have a function that returns a string. This function can accept any
type of object, which determines the structure of the string returned.
My question is, how do I know what type of object is passed in?
What is this function going to do?
If you intend to examine each object given and return a "representation"
of that object for, say, debugging purposes, then /don't/.
Instead, on each of your Classes, /override/ the ToString method and use
/this/ to define the representation of that Class, something like:
Class Person
Public ReadOnly Property Forenames() as String
...
Public ReadOnly Property Initials() as String
...
Public ReadOnly Property Surname() as String
...
Public Overrides Overloads Function ToString() As String
Return Me.Surname & ", " & Me.Initials
End Function
End Class
That way, when given any of your objects, simply using
? x.ToString()
will get you the representation that you've defined for that particular
Class. To get the Type of the object, you'd use
? x.GetType().ToString()
HTH,
Phill W.