【发布时间】:2012-04-13 20:12:36
【问题描述】:
如何实现下面接口中定义的功能?当我在 VS2010 中实现时,如下所示。 MyType 变灰并且不再识别类型?谢谢!
public interface IExample
{
T GetAnything<T>();
}
public class MyType
{
//getter, setter here
}
public class Get : IExample
{
public MyType GetAnything<MyType>()
{ ^^^^^^^ ^^^^^^
MyType mt = new MyType();
^^^^^^^^^^^^^^^^^^^^^^^^^^ /* all greyed out !!*/
}
}
【问题讨论】:
-
这有一种XY Problem 的感觉...
标签: c# generics interface implementation