I’m having trouble with the below code and was hoping someone out there could tell me what’s wrong with it.
The error I’m given is:
Cannot implicitly convert type
ThisThing<T>toT
My code:
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
}
}
Thoughts? I appreciate your help!
You have told the code that the return type for that method is
Tand you are trying to return athisThing<T>. The compiler has no idea how to convert one from the other so it is complaining to you about it.You need to either change the return type for your method or change what you are returning in the method.