我想List
用我的自定义类包装类。至于现在我有这样的东西;
public class PriorityListOfNodes
{
private List<Node> list_;
private IComparer<Node> sorter_;
public List<Node> List_ {
get {return list_;}
set {list_ = value;}
}
public PriorityListOfNodes ()
{
sorter_ = new NodeSorter_fValueDescending ();
}
public Node PopFromEnd ()
{
Node temp = new Node (list_ [list_.Count - 1]);
list_.RemoveAt (list_.Count - 1);
return temp;
}
public Node PeekFromEnd ()
{
return list_ [list_.Count - 1];
}
public void Add (ref Node toAdd)
{
Debug.Log (toAdd);
list_.Add (toAdd);
list_.Sort (sorter_);
}
}
当我现在做
Node temp = new Node(10,20); //custom constructor
PriorityListOfNodes l = new PriorityListOfNodes();
l.add(temp);
我得到运行时异常:
你调用的对象是空的
我也试过没有ref
但结果相同。我在这里做错了什么?