471,627 Members | 1,424 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

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
Jan 11 '06 #1
3 2591
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]
- mv*@spam.guard.caspershouse.com

"David Veeneman" <da****@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP11.phx.gbl...
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

Jan 11 '06 #2
David Veeneman <da****@nospam.com> wrote:
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.


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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 11 '06 #3
Helps a lot! All I had to do was leave off the brackets...
Jan 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Steven Bethard | last post: by
49 posts views Thread by Steven Bethard | last post: by
reply views Thread by crazyone | last post: by
10 posts views Thread by Egghead | last post: by
3 posts views Thread by BombDrop | last post: by
4 posts views Thread by tadmill | last post: by
26 posts views Thread by raylopez99 | last post: by
11 posts views Thread by Scott Stark | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.