有Remember.cs
:
namespace Tasks
{
public class Remember : Task
{
new public string name = typeof(Remember).Name;
new public Task.Priority priority = Task.Priority.High;
}
}
Task.cs
:
public abstract class Task
{
public string name;
public Task.Priority priority = Task.Priority.Low;
public enum Priority
{
High = 3,
Medium = 2,
Low = 1,
}
}
当我使用以下方法创建此类的实例时:
Task task = (Task)Activator.CreateInstance(typeof(Remember));
Debug.Log(task.name + " - " + task.priority);
任务的名称为空,优先级是枚举中可用的最低数字,Task.Priority
而不是选定的数字(高)。
为什么不Activator.CreateInstance
初始化那些变量?