如何将嵌套字典作为参数传递给方法?

时间:2013-04-06 21:19:38

标签: c# generics

我想要一个带参数的方法,比如

public int MyMethod(Dictionary<int, Dictionary<int,int>> myDict)
{
 ...
}

但写这篇文章后,我收到编辑失败的消息,以及以下解释:

  

找不到类型或命名空间名称Dictionary 2'。

我该如何解决这个问题?

1 个答案:

答案 0 :(得分:1)

确保在文件顶部包含using System.Collections.Generic;。或者,您可以使用与代码内联的完整命名空间:

public int MyMethod(System.Collections.Generic.Dictionary<int, System.Collections.Generic.Dictionary<int,int>> myDict)
{

}

(但我想我们都可以从中看到using指令更好一些)

相关问题