ASP.NET数组删除重复值实现代码

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了ASP.NET数组删除重复值实现代码脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

根据这段代码,自己编写了一个小程序作为代码资料参考,方便以后可以直接拿来用,不需要网上找。如果你觉得还不错的话,就把它收藏起来吧!

1.前台代码:

<htML XMlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
  <tITle>数组删除重复值</title> 
</head> 
<body> 
  <form id="form1" runat="server"> 
  <div> 
    数组删除前: 
    <asp:Label ID="lblResult1" runat="server"></asp:Label> 
    <br /> 
    数组删除后: 
    <asp:Label ID="lblResult2" runat="server"></asp:Label> 
  </div> 
  </form> 
</body> 
</html>

2.后台代码:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Collections; //引用 
   
public partial class NetObjects_数组_删除重复值 : System.Web.UI.Page 
{ 
  PRotected void Page_Load(object sender, Eventargs e) 
  { 
    string strNum = "168,145,150,148,333,888,666,168,144"; 
    //输出原数组 
    lblResult1.Text = strNum; 
    string[] arrNum = strNum.Split(','); 
    ArrayList al = new ArrayList(); 
    for (int i = 0; i < arrNum.Length; i++) 
    { 
      //判断数组值是否已经存在 
      if (al.Contains(arrNum[i]) == false) 
      { 
        al.Add(arrNum[i]); 
      } 
    } 
    //把ArrayList转换数组 
    arrNum = new string[al.Count]; 
    arrNum = (string[])al.ToArray(tyPEof(string)); 
    //输出删除后数组 
    string result = ""; 
    for (int j = 0; j < arrNum.Length; j++) 
    { 
      if (j != 0) 
      { 
        result += ","; 
      } 
      result += arrNum[j]; 
    } 
    lblResult2.Text = result; 
  } 
}

3.最终输出效果:

以上就是关于ASP.NET数组删除重复值的实现方法,希望对大家的学习有所帮助。

脚本宝典总结

以上是脚本宝典为你收集整理的ASP.NET数组删除重复值实现代码全部内容,希望文章能够帮你解决ASP.NET数组删除重复值实现代码所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。