c# - “使用”关键字不起作用

标签 c#

我有一个文件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/

相关文章:

c# - 使用 MS Access 插入语句 C#

c# - 如果在 C# 中该窗体发生异常,如何优雅地关闭该窗体

c# - 复杂的数据库操作

c# - C# 中的 Mutex - 从未同步的代码块同步

c# - 在 razor View 中显示格式化的 html

c# - 在 .NET 中比较不同的数字类型(int、float、double、...)

c# - 发送 httprequest 以接收一些数据

c# - 是否可以创建一个快捷方式来将未使用的 usings 删除到一个类中?

c# - 为什么这个重写的方法变灰了?

c# - MongoDb c# 2.0 驱动程序 - 我如何计算服务器上的聚合计数?