KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a generic method which is to return an object of the generic type. Some code: public static T Foo<T>(string value) { if (typeof(T) == typeof(String)) return value; if (typeof(T) == typeof(int)) return Int32.Parse(value); // Do more stuff } I can see that the compiler might complain about this ( "Cannot convert type 'String' to 'T'" ), even if the code shouldn't cause any logical errors runtime. Is there any way to achieve what I'm looking for? Casting doesn't help...
Tags (comma-separated)
Save Edits
Cancel