如何为IDictionary <int,string>创建实例?

Kav*_* P. 0 c# asp.net-mvc razor

我有我的模特,

public IDictionary<int, string> QuestionSetList { get; set; }
Run Code Online (Sandbox Code Playgroud)

我不能在我的控制器中使用这个QuestionSetList,当它执行时,它抛出一个NullReferenceException,说:对象引用没有设置为对象的实例.我有我的代码,

model.QuestionSetList.Add(QuestionSetNo,QuestionSetTopic);
Run Code Online (Sandbox Code Playgroud)

请告诉我如何解决这个问题.

Sel*_*enç 8

您无法实例化接口,因为接口只是合同.它没有任何实现.

您需要实例化实现该接口的类型.在这种情况下,您可以使用Dictionary<int, string>哪个实现IDictionary<int, string>.