Now if only the ide would fill in the inferred type for me....then I would be very happy.....I suppose there isn't a way of doing that?
(my generics are very convoluted). -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark Sent: 05 December 2007 14:34 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] type inference and extension methods.... Nope...you're completely correct....my contrived example does work...what was confusing me was intellisense showing the extension method as "Foo<>()"....when if fact it had inferred the type parameters. -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Nicholls, Mark Sent: 05 December 2007 14:20 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] type inference and extension methods.... Let me have a go...I may be talking nonsense....if your code works (and I'm sure it does)...it would seem that the 'T' is required for the declaration but not the call...which is reasonable.... I discovered this with a more complicated example and used IList as a simple example....I'm either completely wrong, or the example is too simple. -----Original Message----- From: Discussion of advanced .NET topics. [mailto:[EMAIL PROTECTED] On Behalf Of Fabian Schmied Sent: 05 December 2007 14:01 To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM Subject: Re: [ADVANCED-DOTNET] type inference and extension methods.... > I've been messing about with extension methods and noticed something, not > wrong, but slightly limited about them, and wondered why. [...] > static T GetFirstElement<T>(this System.Collections.Generic.IList<T> list) [...] > should be enough....i.e. it should be able to infer 'T'...without it being > specified explicitly This works for me. In fact, Enumerable.First() is defined with a similar signature. Can you give a full example program for your problem? My code: using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication4 { public static class S { public static T GetFirstElement<T>(this System.Collections.Generic.IList<T> list) { return list[0]; } } class Program { static void fooBar(IList<string> foo) { string s = foo.GetFirstElement(); // this should be enough } } } Fabian =================================== 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(r) http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com =================================== 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