我有这段代码(为了清晰起见进行了最小化):
interface IEither<out TL, out TR> {
}
class Left<TL, TR> : IEither<TL, TR> {
public Left(TL value) { }
}
static class Either {
public static IEither<TL, TR> Left<TL, TR> (this TL left) {
return new Left<TL, TR> (left);
}
}
为什么我不能说:
static class Foo
{
public static IEither<string, int> Bar ()
{
//return "Hello".Left (); // Doesn't compile
return "Hello".Left<string, int> (); // Compiles
}
}
我收到一个错误提示,指出'string'不包含名为'Left'的定义,并且找不到接受类型为'string'的第一个参数的扩展方法'Left'(是否缺少使用指令或程序集引用?)(CS1061)
。
Foo
和Bar
是什么。你能发一个完整的可重现的示例吗? - Sriram Sakthivel