怎样去掉数组里重复的数据?

eminem346 2008-08-04 04:26:48
ArrayList array3_11 = new ArrayList();

for (int t = 0; t < ds.Tables[0].Rows.Count; t++)
{
if (ds.Tables[0].Rows[t]["moneytype"].ToString().Trim() == "USD")
{
array3_11.Add(ds.Tables[0].Rows[t]["invoiceuserid"].ToString().Trim());



怎样去掉数组里面重复的数据啊? 请高手指教

...全文
172 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
wanghui0380 2008-08-04
  • 打赏
  • 举报
回复
如果是net3.0以上的化,直接用linq查询也可以

呵呵,实际上linq大体上是用匿名方法做,so,net2.0下我们一样可以仿照linq的东西,写匿名方法完成同样的事情
wanghui0380 2008-08-04
  • 打赏
  • 举报
回复
参考
http://msdn.microsoft.com/zh-cn/library/wec2b2e6(VS.80).aspx
wanghui0380 2008-08-04
  • 打赏
  • 举报
回复
既然有datatable对象,那就直接用datatable的toTable方法把
DataTable uniqueTable = dvwDataView.ToTable(true, "name");

具体参数请参msdn,该方法是按照你的要求copy一张表出来

eminem346 2008-08-04
  • 打赏
  • 举报
回复
Contains 这个方法怎么用阿?
weinaxxc 2008-08-04
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 HonorsOffice 的回复:]
既然用了ArrayList就可以使用它自带的Contains方法。
[/Quote]
bollton 2008-08-04
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 sportdog 的回复:]
同意加入时判断数组中是否已经重复了。
[/Quote]
sportdog 2008-08-04
  • 打赏
  • 举报
回复
同意加入时判断数组中是否已经重复了。
oec2003 2008-08-04
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 cpp2017 的回复:]
C# code ArrayList al = new ArrayList();
al.Add("4");
al.Add("2");
al.Add("1");
al.Add("3");
al.Add("2");
al.Add("3");
al.Add("1");
al.Sort();
for (int i = 1; i < al.Count; i++)
{
if (al[i] == al[i - 1])
{
al.Rem…
[/Quote]
brooklyng60 2008-08-04
  • 打赏
  • 举报
回复
ArrayList al = new ArrayList();
for (int i = 0; i < dt.rows.count-1; i++)
{
if (!al.Contains(.....))
{
al.Add(...);
}
}
HonorsOffice 2008-08-04
  • 打赏
  • 举报
回复
既然用了ArrayList就可以使用它自带的Contains方法。
Lee_Moon 2008-08-04
  • 打赏
  • 举报
回复
ArrayList array3_11 = new ArrayList();
string s = "";
for (int t = 0; t < ds.Tables[0].Rows.Count; t++)
{
if (ds.Tables[0].Rows[t]["moneytype"].ToString().Trim() == "USD")
{
string str = ds.Tables[0].Rows[t]["invoiceuserid"].ToString().Trim();
if(s.indexof("|" + str + "|") < 0)
{
array3_11.Add(str);
s += "|" +str + "|";
}



这样不用循环数组
accomp 2008-08-04
  • 打赏
  • 举报
回复
ArrayList array3_11 = new ArrayList();

for (int t = 0; t < ds.Tables[0].Rows.Count; t++)
{
if (ds.Tables[0].Rows[t]["moneytype"].ToString().Trim() == "USD")
{
if(!array3_11.contants(ds.Tables[0].Rows[t]["invoiceuserid"].ToString().Trim())){
array3_11.Add(ds.Tables[0].Rows[t]["invoiceuserid"].ToString().Trim());
}


wuhaojun135 2008-08-04
  • 打赏
  • 举报
回复
加个判断一样不要加进去就OK了啊
cpp2017 2008-08-04
  • 打赏
  • 举报
回复
   ArrayList al = new ArrayList();
al.Add("4");
al.Add("2");
al.Add("1");
al.Add("3");
al.Add("2");
al.Add("3");
al.Add("1");
al.Sort();
for (int i = 1; i < al.Count; i++)
{
if (al[i] == al[i - 1])
{
al.RemoveAt(i);
i--;
}
}
foreach (string str in al)
{
Response.Write(str + "<BR>");
}

62,074

社区成员

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

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

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

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