Cast generic type parameter to a specific type in C#

You can use Convert.ChangeType

SomeClass obj2 = (SomeClass)Convert.ChangeType(t, typeof(SomeClass));

Although, keep in mind that this will throw an exception if a cast is invalid.

Leave a Comment