implicitly casting a generic<T> back to T

.net, .net-3.5, c#, generics

Solution

Well, yes, but for the love of zombie jesus do NOT do that. It's really confusing. You're slightly misunderstanding the purpose of generics, I think. It's not used to "turn" a class into that type, it's used to have that type (MyGenericString) be 'aware' of the type you want, for various purposes (typically those are collection-based purposes).

Problem

If I write a generic class like class `MyGeneric<T>` is it possible to write an implicit cast to type T, so I can do stuff like: ``` public class MyGeneric<T> { ... } public class GenericProperties { public MyGeneric<string> MyGenericString {get;set;} public void UseMyGeneric() { string sTest = MyGenericString; MyGenericString = "this is a test"; } } ``` Is it possible to do that by overloading operators? I know it could be done if my class wasn't a generic...

Original source