我有一个文件Dictionary.cs
:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Dictionary
{
public SortedDictionary<string, List<WordForm>> wordList { get; set; }
public Dictionary<string, Word> dictionary { get; set; }
public struct WordForm
{
public string rootWord { get; set; }
public string formIdentifier { get; set; }
}
}
当我尝试构建项目时,出现以下错误:
Error 1 The type or namespace name 'SortedDictionary' could not be found (are you missing a using directive or an assembly reference?) C:\Users\Chris\Documents\Visual Studio 2013\Projects\Midlife\Dictionary.cs
据我所知,using System.Collections.Generic;
允许我使用 SortedDictionary
。但它抛出一个错误,我不知道为什么。我可以很好地使用 Dictionary
。有什么明显的我想念的吗?
最佳答案
SortedDictionary
位于 System.Collections.Generic
中,但您需要确保已获得对 System.dll
的引用,因为这是包含该类的程序集。
尽管 Dictionary
位于 System.Collections.Generic
中,但它存在于不同的程序集中,mscorlib.dll
已被每个项目引用从 C# 1.0 开始
要查看您引用的内容,请转到解决方案资源管理器中的项目。您应该会看到一个名为“引用”的可扩展部分。展开它并查看是否列出了“系统”。如果没有,则右键单击“引用”并选择“添加引用”。将出现一个对话框,在“框架”下的“程序集”部分向下滚动,直到找到“系统”并确保选中左侧出现的复选框。关闭并重建。
关于c# - “使用”关键字不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21512237/