C# syntax question Generic and overriding
public class GameEvent
{
public virtual void OnRaise()
{
}
public virtual void OnRaise<T>(T arg)
{
}
}
This is the parent class.
public class OneArg<T> : GameEvent
{
public List<UnityEvent<T>> Events { get; set; }
public event UnityAction<T> OnRaised;
public new void OnRaise<T1>(T1 arg) where T1 : T
{
for (int i = Events.Count - 1; i >= 0; i--)
{
Events[i].Invoke(arg);
}
}
}
And this is child class.
public class OneArg<T> : GameEvent
{
public List<UnityEvent<T>> Events { get; set; }
public event UnityAction<T> OnRaised;
public override void OnRaise<T1>(T1 arg) where T1 : T
{
for (int i = Events.Count - 1; i >= 0; i--)
{
Events[i].Invoke(arg);
}
}
}
And this one is also the same as above. Except for only one keyword that new keyword is replaced with override. Second class with new keyword doesn't occur errors but, the last one occurs errors. The error is 'Argument 1 : cannot convert from T1 to T'. I have no ideas why this error occurred when I use override. So my question is that I want to make type T equal to T1. How can I achieve this?
Your answer
Follow this Question
Related Questions
Protected variable is assigned in parent but null in child 1 Answer
Question About Unity Class Hierarchy 3 Answers
Overriding Start(), is this just bad code? 1 Answer
inheritance - using base class member variables 2 Answers
Variable containing a transform is modifying the object's transform it is referenced to. 1 Answer