ASP.NET數組重複資料刪除值實現代碼_實用技巧

來源:互聯網
上載者:User

根據這段代碼,自己編寫了一個小程式作為代碼資料參考,方便以後可以直接拿來用,不需要網上找。如果你覺得還不錯的話,就把它收藏起來吧!

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數組重複資料刪除值的實現方法,希望對大家的學習有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.