Pat*_*ryk 6 c# runtime-error nullreferenceexception
我想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_);
}
}
Run Code Online (Sandbox Code Playgroud)
我什么时候做
Node temp = new Node(10,20); //custom constructor
PriorityListOfNodes l = new PriorityListOfNodes();
l.add(temp);
Run Code Online (Sandbox Code Playgroud)
我得到运行时异常:
你调用的对象是空的
我也试过没有,ref但结果相同.我在这做错了什么?
你实际上从未实例化过List<Node>.
public PriorityListOfNodes ()
{
sorter_ = new NodeSorter_fValueDescending ();
list_ = new List<Node>();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8813 次 |
| 最近记录: |