ASP.NET數組刪除重復值實現代碼
來源:懂視網
責編:小采
時間:2020-11-27 22:38:08
ASP.NET數組刪除重復值實現代碼
ASP.NET數組刪除重復值實現代碼:根據這段代碼,自己編寫了一個小程序作為代碼資料參考,方便以后可以直接拿來用,不需要網上找。如果你覺得還不錯的話,就把它收藏起來吧! 1.前臺代碼: <html xmlns=http://www.w3.org/1999/xhtml> <head runat=ser
導讀ASP.NET數組刪除重復值實現代碼:根據這段代碼,自己編寫了一個小程序作為代碼資料參考,方便以后可以直接拿來用,不需要網上找。如果你覺得還不錯的話,就把它收藏起來吧! 1.前臺代碼: <html xmlns=http://www.w3.org/1999/xhtml> <head runat=ser
根據這段代碼,自己編寫了一個小程序作為代碼資料參考,方便以后可以直接拿來用,不需要網上找。如果你覺得還不錯的話,就把它收藏起來吧!
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.最終輸出效果:

聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
ASP.NET數組刪除重復值實現代碼
ASP.NET數組刪除重復值實現代碼:根據這段代碼,自己編寫了一個小程序作為代碼資料參考,方便以后可以直接拿來用,不需要網上找。如果你覺得還不錯的話,就把它收藏起來吧! 1.前臺代碼: <html xmlns=http://www.w3.org/1999/xhtml> <head runat=ser