I have the psuedocode
T foo<T>(string bar)
{
if (typeof(T) == typeof(string))
{
return bar;
}
...
Although the code doesnt really make much sense , is it possible to get something similar to above working?
Ive tried return (T)bar and return bar as T to no avail.
edit: Apologies, pseudocode corrected.
You can do that:
But if you’re doing something different depending on the type of T, you should probably reconsider your design… perhaps generics are not the best option for what you’re trying to do.