.NET 3.5中的HashSet 有什么特别之处?

时间:2023-01-15 20:26:54

Here's an interesting puzzle.

这是一个有趣的谜题。

I downloaded Snippet Compiler to try some stuff out, and wanted to write the following code:

我下载了Snippet Compiler来尝试一些东西,并想编写以下代码:

using System;
using System.Collections.Generic;

public class MyClass
{
    public static void RunSnippet()
    {
        HashSet<int> h = new HashSet<int>();
    }
}

But the above code doesn't compile. I get:

但是上面的代码没有编译。我明白了:

"The type or namespace name 'HashSet' could not be found (are you missing a using directive or an assembly reference?)"

“无法找到类型或命名空间名称'HashSet'(您是否缺少using指令或程序集引用?)”

Clearly I'm not. It seems it can't find HashSet, yet it finds other types in the Systems.Collections.Generic namespace (e.g. List, SortedDictionary).

显然我不是。它似乎无法找到HashSet,但它在Systems.Collections.Generic命名空间中找到其他类型(例如List,SortedDictionary)。

What's the explanation for this? Presumeably Snippet Compiler is just using the standard Framework compiler under the covers...

对此有何解释?假设Snippet Compiler正在使用标准的Framework编译器......

I would be interested to know why this doesn't work.

我很想知道为什么这不起作用。

2 个解决方案

#1


4  

Check what version of System.Core.dll Snippet Compiler is using.

检查System.Core.dll Snippet编译器正在使用的版本。

#2


5  

is your reference use

是你的参考用途

Namespace: System.Collections.Generic

Assembly: System.Core (in System.Core.dll)

程序集:System.Core(在System.Core.dll中)

version 3.5?

#1


4  

Check what version of System.Core.dll Snippet Compiler is using.

检查System.Core.dll Snippet编译器正在使用的版本。

#2


5  

is your reference use

是你的参考用途

Namespace: System.Collections.Generic

Assembly: System.Core (in System.Core.dll)

程序集:System.Core(在System.Core.dll中)

version 3.5?