Generic return value

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David Veeneman

    #1

    Generic return value

    I'm writing a custom Find() function on a collection class derived from
    List<T>. The function will return an object of the type held in the
    collection.

    How do I specify the return type of the function? Thanks.

    --
    David Veeneman
    Foresight Systems


  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Generic return value

    David,

    You can just do:

    public T Find()
    {
    }

    This assumes that T is the generic type parameter declared on the class
    level.

    Hope this helps.


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "David Veeneman" <davidv@nospam. com> wrote in message
    news:uMwu68uFGH A.1396@TK2MSFTN GP11.phx.gbl...[color=blue]
    > I'm writing a custom Find() function on a collection class derived from
    > List<T>. The function will return an object of the type held in the
    > collection.
    >
    > How do I specify the return type of the function? Thanks.
    >
    > --
    > David Veeneman
    > Foresight Systems
    >[/color]


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: Generic return value

      David Veeneman <davidv@nospam. com> wrote:[color=blue]
      > I'm writing a custom Find() function on a collection class derived from
      > List<T>. The function will return an object of the type held in the
      > collection.
      >
      > How do I specify the return type of the function? Thanks.[/color]

      Just specify it as T. Look at the docs for the indexer etc for samples.

      --
      Jon Skeet - <skeet@pobox.co m>
      http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
      If replying to the group, please do not mail me too

      Comment

      • David Veeneman

        #4
        Re: Generic return value

        Helps a lot! All I had to do was leave off the brackets...


        Comment

        Working...