3
有Remember.cs
:C#Activator.CreateInstance不初始化瓦爾
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
enum r中可用的最小編號ather比選定的一個(高)。
爲什麼Activator.CreateInstance
不能初始化這些變量?
是什麼讓你覺得這與Activator.CreateInstance有關?你應該看到'Task task = new Remember();'? – hvd