locked
Function that can receive diffrent type of parameter RRS feed

  • Question

  • User-1812347337 posted

    Hi,

    Is it possible in VB to have a function that can receive diffrent parameter, like a String or a Integer or a custom class type?

     

    Thanks

    Thursday, March 10, 2011 11:12 AM

Answers

  • User397347636 posted

    Function yourFunction(Of T)(ByVal yourParam As List(Of T)) As String

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 10, 2011 5:14 PM

All replies

  • User1224194097 posted

    You have to make the parameter type as Object and check for ObjectType in your code to perform different tasks based on the parameter type.

    Thursday, March 10, 2011 12:48 PM
  • User-1812347337 posted

    Ok... I think I'll explain more what I want...

    Right now I have 10 functions that does the same thing... the problem is that they are using different type. Each function receive a List(Of T) where T is a type (Interger or String or custom class, ...) and an iteger that is an index. The function return the ToString() of the element in the index position or -1 of the index is out of range.

    What I want is ONE function that can take a List(Of T) where T can be any type including custom class and an integer (the index) and return the ToString() of the position of the index (or -1 if the index is out of range)

    Is this possible in VB.NET?

     

    Thanks

    Thursday, March 10, 2011 1:20 PM
  • User397347636 posted

    Function yourFunction(Of T)(ByVal yourParam As List(Of T)) As String

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 10, 2011 5:14 PM
  • User-1812347337 posted

    Thanks, it works perfectly!!

    Monday, March 14, 2011 8:28 AM