class GenericClass<T> : SomeBaseClass where T : SomeBaseClass { public T GetT() { return this as T; } } Question: This code works, but I do not understand how. If T is a kind of SomeDerrivedClass that inherits from SomeBaseClass, then how does the conversion of this (i.e., GenericClass <T> instance) to type T occur?
UPD: set foot, the GetT () method returns null, yes. The question arose during the reading of this article on Habré: the link to the article There is given such code:
public class MonoBehaviourSingleton<T> : MonoBehaviour where T : MonoBehaviour { public static T Instance; protected virtual void Awake() { Instance = GetInstance(); } protected T GetInstance() { return this as T; } }
null, since this transformation is impossible. - rdornDerrivedClassdoesDerrivedClasslookDerrivedClass? - Grundy