在不区分大小写的模式下如何使用HashSet< string> .Contains()方法? [英] How to use HashSet<string>.Contains() method in case -insensitive mode?
本文介绍了在不区分大小写的模式下如何使用HashSet< string> .Contains()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在不区分大小写的模式下如何使用 HashSet< string> .Contains()
方法?
How to use HashSet<string>.Contains()
method in case -insensitive mode?
推荐答案
您可以使用自定义比较器创建 HashSet
:
You can create the HashSet
with a custom comparer:
HashSet<string> hs = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
hs.Add("Hello");
Console.WriteLine(hs.Contains("HeLLo"));
这篇关于在不区分大小写的模式下如何使用HashSet< string> .Contains()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文