I've been messing about with extension methods and noticed something, not wrong, but slightly limited about them, and wondered why.
If I create an extension method that returns the first element of a generic list....you would expect the signature to be.... static T GetFirstElement<T>(this System.Collections.Generic.IList<T> list) now clearly the compiler can and does recognise this as a valid extension method on IList<>....but what seems odd is that it requires me to specify "T" in the method, as it is implicitly defined in the 'this' parameter....i.e. static T GetFirstElement(this System.Collections.Generic.IList<T> list) should be enough....i.e. it should be able to infer 'T'...without it being specified explicitly i.e. void fooBar(IList<string> foo) { string s = foo.GetFirstElement(); // this should be enough } but it complains....it wants T to be explicitly defined in the method call (and signature), even though there is actually only 1 type it can possibly be. Am I missing something? =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com