Created a script like the following to define a class called ScrollViewController, and I want to inherit it in multiple classes. At this time, I prepared a virtual property named DataList with a generic type list as its element, and I want to allow specifying the data type in the child classes.
ScrollViewController.cs
abstract class ScrollViewController<T> : MonoBehaviour
{
protected virtual List<T> DataList
{
get { return dataList; }
set { dataList = value; }
}
private List<T> dataList;
}
EngineerScrollViewController.cs
class EngineerScrollViewController : ScrollViewController<Engineer>
{
private List<Engineer> dataList = new List<Engineer>();
protected override List<Engineer> DataList
{
get { return dataList; }
set { dataList = value; }
}
}
However, I encountered an error message like below. Do you have any solutions to resolve this?
Assets/Scripts/ScrollViewController.cs(51,24): error CS0029: Cannot implicitly convert type 'System.Collections.Generic.List<Engineer>' to 'System.Collections.Generic.List<T>'
The article I referred to:
https://stackoverflow.com/questions/63383863/declare-generic-list-as-member-of-parent-class