我在与下面的代码的麻烦,并希望有人在那里能告诉我什么地方错了。“无法隐式转换类型‘thisMethod <T>’到‘T’”
我给出的错误是:
无法隐式转换类型
ThisThing<T>
到T
我的代码:
class ThisThing<T>
{
public string A { get; set; }
public string B { get; set; }
}
class OtherThing
{
public T DoSomething<T>(string str)
{
T foo = DoSomethingElse<T>(str);
return foo;
}
private T DoSomethingElse<T>(string str)
{
ThisThing<T> thing = new ThisThing<T>();
thing.A = "yes";
thing.B = "no";
return thing; // This is the line I'm given the error about
}
}
的思考?我感谢您的帮助!
请有资金,都使得它容易得多阅读启动类型名称。而且,请不要用下划线启动局部变量。或者,如果你这样做,用下划线开始它们。这将帮助我们(更重要的是你)阅读代码并防止错误。 – 2012-01-17 11:24:00