■■■命名空间名称“HashSet”是什么? 如何解决■■■

fanqingfeng 2008-04-10 10:39:03
我学习了你分享的这几篇好文
《忽略大小写的.NET脏字过滤算法 》http://www.cnblogs.com/xingd/archive/2008/02/04/1064549.html

,也尝试自己组合弄弄,便宜过程中发现一个错误一直想不到解决办法:
###############################

编译器错误信息: CS0246: 找不到类型或命名空间名称“HashSet”(是否缺少 using 指令或程序集引用?)

源错误:



行 17: public class ClearBadword
行 18: {
行 19: private HashSet<string> hash = new HashSet<string>();
行 20: private byte[] fastCheck = new byte[char.MaxValue];
行 21: private byte[] fastLength = new byte[char.MaxValue];



###############################


我的代码前面部分是这样写的:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
/// <summary>
/// ClearBadword 的摘要说明
/// </summary>
public class ClearBadword
{
private HashSet<string> hash = new HashSet<string>(); private byte[] fastCheck = new byte[char.MaxValue];
private byte[] fastLength = new byte[char.MaxValue];
private BitArray charCheck = new BitArray(char.MaxValue);
private BitArray endCheck = new BitArray(char.MaxValue);
private int maxWordLength = 0;
private int minWordLength = int.MaxValue;



========
请指教 谢谢
...全文
440 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
超级大笨狼 2008-04-10
  • 打赏
  • 举报
回复
java.util.HashSet
一品梅 2008-04-10
  • 打赏
  • 举报
回复
System.Collections
jinjazz 2008-04-10
  • 打赏
  • 举报
回复
泛型的集合都在System.Collections.Generic 下面
超级大笨狼 2008-04-10
  • 打赏
  • 举报
回复
System.Collections.Generic
lovehongyun 2008-04-10
  • 打赏
  • 举报
回复
看看..
wxg22526451 2008-04-10
  • 打赏
  • 举报
回复
命名空间: System.Collections.Generic
程序集: System.Core(在 System.Core.dll 中)
叶子 2008-04-10
  • 打赏
  • 举报
回复
你就是缺少个类
叶子 2008-04-10
  • 打赏
  • 举报
回复
HashSet扩展AbstractSet并且实现Set接口。它创建一个类集,该类集使用散列表进行存
储。正像大多数读者很可能知道的那样,散列表通过使用称之为散列法的机制来存储信息。
在散列(hashing)中,一个关键字的信息内容被用来确定唯一的一个值,称为散列码(hash
code)。而散列码被用来当做与关键字相连的数据的存储下标。关键字到其散列码的转换
是自动执行的??你看不到散列码本身。你的程序代码也不能直接索引散列表。散列法的
优点在于即使对于大的集合,它允许一些基本操作如add( ),contains( ),remove( )和size( )
方法的运行时间保持不变。
下面的构造函数定义为:
HashSet( )
HashSet(Collection c)
HashSet(int capacity)
HashSet(int capacity, float fillRatio)
第一种形式构造一个默认的散列集合。第二种形式用c中的元素初始化散列集合。第三
种形式用capacity初始化散列集合的容量。第四种形式用它的参数初始化散列集合的容量和
填充比(也称为加载容量)。填充比必须介于0.0与1.0之间,它决定在散列集合向上调整大
小之前,有多少能被充满。具体的说,就是当元素的个数大于散列集合容量乘以它的填充
比时,散列集合被扩大。对于没有获得填充比的构造函数,默认使用0.75。
HashSet没有定义任何超过它的超类和接口提供的其他方法。
重要的是,注意散列集合并没有确保其元素的顺序,因为散列法的处理通常不让自己
参与创建排序集合。如果需要排序存储,另一种类集??TreeSet将是一个更好的选择。
这里是一个说明HashSet的例子。
// Demonstrate HashSet.
import java.util.*;
class HashSetDemo {
public static void main(String args[]) {
// create a hash set
HashSet hs = new HashSet();
// add elements to the hash set
hs.add("B");
hs.add("A");
hs.add("D");
hs.add("E");
hs.add("C");
hs.add("F");

System.out.println(hs);
}
}
下面是该程序的输出:
[A, F, E, D, C, B]
rtsp 2008-04-10
  • 打赏
  • 举报
回复
很清楚了。。要么找到这个类,要么自己写出这个类
fanqingfeng 2008-04-10
  • 打赏
  • 举报
回复
private HashSet <string> hash = new HashSet <string>();


请问这需要引入什么命名空间?

62,242

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧