You shouldn't have to...I think...theoretically...

If we do it the other way around....

static T GetFirstElement<T>(this System.Collections.Generic.IList<T>
list)
...

string s = foo.GetFirstElement<?>(); // what types can we specify as '?'

? has to be string...because foo is of type IList<string>...thus T is
string (according to this System.Collections.Generic.IList<T> list).
....thus ? *must* be string...if I put anything else in at all it will
(I think) complain...

Its as if it's done the hard bit....but then asks you to put in more
information for the sake of it. 

-----Original Message-----
From: Discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED] On Behalf Of Per Bolmstedt
Sent: 05 December 2007 13:58
To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM
Subject: Re: [ADVANCED-DOTNET] type inference and extension methods....

Mark Nicholls wrote:

 > static T GetFirstElement<T>(this System.Collections.Generic.IList<T>
list)
 >   string s = foo.GetFirstElement(); // this should be enough

If I'm not missing something subtle here:

If the method is defined as GetFirstElement<T>, then you must supply T
when
calling it. This has no relation to extension methods, right?

===================================
This list is hosted by DevelopMentor(r)  http://www.develop.com

View archives and manage your subscription(s) at
http://discuss.develop.com

===================================
This list is hosted by DevelopMentorĀ®  http://www.develop.com

View archives and manage your subscription(s) at http://discuss.develop.com

Reply via email to