0

C# 3.5: I can't get this code to compile:

HashSet<string> classDeclarations = new HashSet<string>(StringComparison.InvariantCultureIgnoreCase);

I get this error:

Argument 1: cannot convert from 'System.StringComparison' to 'System.Collections.Generic.IEqualityComparer'

So I can't pass a comparison?

4

2 回答 2

8

StringComparison是许多与字符串相关的函数使用的枚举。
由于HashSet<T>与字符串无关,因此采用StringComparison.

您需要使用StringComparer实现IEqualityComparer<String>.

于 2012-08-14T13:05:03.733 回答
7

你需要这样做

HashSet<string> myHashSet = new HashSet<string>(StringComparer.InvariantCultureIgnoreCase);
于 2012-08-14T13:06:09.513 回答