当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET数组删除重复值实现代码

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

2017年12月12日  | 移动技术网IT编程  | 我要评论

安卓捕鱼达人2破解版,中行进度查询,腾讯产品侵权遭起诉

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

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数组删除重复值的实现方法,希望对大家的学习有所帮助。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网