> 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Ā® http://www.develop.com
View archives and manage your subscription(s) at http://discuss.develop.com