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

来源:互联网  时间:2016/8/11 19:23:56

关于网友提出的“命名空间 ■■■命名空间名称“HashSet”是什么? 如何解决■■■”问题疑问,本网通过在网上对“命名空间 ■■■命名空间名称“HashSet”是什么? 如何解决■■■”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:命名空间 ■■■命名空间名称“HashSet”是什么? 如何解决■■■
描述:

我学习了你分享的这几篇好文
《忽略大小写的.NET脏字过滤算法 》http://www.cnblogs.com/xingd/archive/2008/02/04/1064549.html
,也尝试自己组合弄弄,便宜过程中发现一个错误一直想不到解决办法: 
############################### 
编译器错误信息: CS0246: 找不到类型或命名空间名称“HashSet”(是否缺少 using 指令或程序集引用?) 
源错误: 
行 17: public class ClearBadword 
行 18: { 
行 19: private HashSet hash = new HashSet(); 
行 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; 
/// 

 
/// ClearBadword 的摘要说明 
/// 
 
public class ClearBadword 

private HashSet hash = new HashSet(); 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; 
======== 
请指教 谢谢


解决方案1:

java.util.HashSet

解决方案2:

System.Collections.Generic 

解决方案3:

System.Collections

解决方案4:

泛型的集合都在System.Collections.Generic  下面

解决方案5:

命名空间:  System.Collections.Generic
程序集:  System.Core(在 System.Core.dll 中)

解决方案6:

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]

上一篇请问前台网页如何执行后台代码?
下一篇那位有SharePoit数据库关图请给我发一份。 E—mail:abc130103@163com
明星图片
相关文章
《命名空间 ■■■命名空间名称“HashSet”是什么? 如何解决■■■》由码蚁之家搜集整理于网络,
联系邮箱:mxgf168#qq.com(#改为@)