我定义一个类属性的算法如下:带参数的重新定义性能
public InputParametersProperty InputParameters { get; set; }
public class InputParametersProperty
{
private Dictionary<string, object> inputParameters = new Dictionary<string, object>();
public object this[string name]
{
get { return inputParameters[name]; }
set
{
if (inputParameters == null)
inputParameters = new Dictionary<string, object>();
else
inputParameters.Add(name, value);
}
}
}
从另一个类我想用表格的属性:
algorithm.InputParameters["populationSize"] = 100;
但我得到的错误:Object reference not set to an instance of an object
在你的构造函数'algorithm',你设置'InputParameters'到一个新的'InputParametersProperty'对象呢,还是留为空? – krillgar 2013-03-05 20:47:07