找不到哈希表的类型或命名空间。您是否缺少程序集引用? [英] the type or namespace for hashtable is not found .are you missing an assembly reference?

查看:118
本文介绍了找不到哈希表的类型或命名空间。您是否缺少程序集引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的下面的代码中我得到了错误 -

找不到哈希表的类型或命名空间。你是否缺少程序集引用?

code is-

in my following code i get the error -
the type or namespace for hashtable is not found .are you missing an assembly reference?
code is-

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
SqlConnection con = new SqlConnection("Data Source=SureshDasari; Initial Catalog=MySampleDB; Integrated Security=true");
con.Open();
SqlCommand cmd = new SqlCommand("select * from SampleTable", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds,"UserDetails");
DataTable dt = ds.Tables["UserDetails"];
RemoveDuplicateRows(dt, "UserName"); // Here UserName is Column name of table
gvDetails.DataSource = ds;
gvDetails.DataBind();
}
}
// This method is used to delete duplicate rows of table
public DataTable RemoveDuplicateRows(DataTable dTable, string colName)
{
    Hashtable hTable = new Hashtable();
    ArrayList duplicateList = new ArrayList();
    foreach (DataRow dtRow in dTable.Rows)
    {
        if (hTable.Contains(dtRow[colName]))
            duplicateList.Add(dtRow);
        else
            hTable.Add(dtRow[colName], string.Empty);
    }
    foreach (DataRow dtRow in duplicateList)
        dTable.Rows.Remove(dtRow);
    return dTable;
}



使用的引用是 -


the references used are-

using System;
using System.Configuration;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
using MySql.Data.MySqlClient;
using System.Text;
using System.Net;
using System.Net.Mail;
using System.Data;





请提出建议做



please suggest what to do

推荐答案

你需要一个

You need a
using System.Collections;



Hashtable 是一个非泛型集合,因此它位于该命名空间中。 br $> b $ b

编辑:



强烈建议您在有的时候使用通用收藏品没有很好的理由不去。因此,没有Hashtable,没有ArrayList以及其他任何 * 。而是字典< TKey,TValue>,List< T>,HashSet< T>等等。你获得了编译时类型安全,这是值得的(为了避免错误)和价值类型的小性能提升(没有装箱/拆箱)。



另一个编辑:

* 请参阅下面谢尔盖的评论。有一些集合没有通用的实现,所以对于那些我的上述建议将不适用。


Hashtable is a non-generic collection, so it sits in that namespace.



I strongly suggest you use generic collections whenever there is no very good reason not to. So, no Hashtable, no ArrayList and whatever else there is*. Instead Dictionary<TKey, TValue>, List<T>, HashSet<T> and so forth. You gain compile-time type-safety which is worth a lot (in order to avoid bugs in the first place) and also small performance gains for value-types (no boxing/unboxing).

Another
* Please see Sergey's comments below. There are some collections of which there is no generic implementation, so for those my above suggestion would not be applicable.


这篇关于找不到哈希表的类型或命名空间。您是否缺少程序集引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆