ASP.NET數(shù)組刪除重復(fù)值實(shí)現(xiàn)代碼
根據(jù)這段代碼,自己編寫(xiě)了一個(gè)小程序作為代碼資料參考,方便以后可以直接拿來(lái)用,不需要網(wǎng)上找。如果你覺(jué)得還不錯(cuò)的話(huà),就把它收藏起來(lái)吧!
1.前臺(tái)代碼:
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>數(shù)組刪除重復(fù)值</title> </head> <body> <form id="form1" runat="server"> <div> 數(shù)組刪除前: <asp:Label ID="lblResult1" runat="server"></asp:Label> <br /> 數(shù)組刪除后: <asp:Label ID="lblResult2" runat="server"></asp:Label> </div> </form> </body> </html>
2.后臺(tái)代碼:
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_數(shù)組_刪除重復(fù)值 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string strNum = "168,145,150,148,333,888,666,168,144"; //輸出原數(shù)組 lblResult1.Text = strNum; string[] arrNum = strNum.Split(','); ArrayList al = new ArrayList(); for (int i = 0; i < arrNum.Length; i++) { //判斷數(shù)組值是否已經(jīng)存在 if (al.Contains(arrNum[i]) == false) { al.Add(arrNum[i]); } } //把ArrayList轉(zhuǎn)換數(shù)組 arrNum = new string[al.Count]; arrNum = (string[])al.ToArray(typeof(string)); //輸出刪除后數(shù)組 string result = ""; for (int j = 0; j < arrNum.Length; j++) { if (j != 0) { result += ","; } result += arrNum[j]; } lblResult2.Text = result; } }
3.最終輸出效果:
以上就是關(guān)于ASP.NET數(shù)組刪除重復(fù)值的實(shí)現(xiàn)方法,希望對(duì)大家的學(xué)習(xí)有所幫助。
- asp.net 字符串、二進(jìn)制、編碼數(shù)組轉(zhuǎn)換函數(shù)
- asp.net 判斷數(shù)組是否存在某個(gè)值的方法
- asp.net(c#) 使用Rex正則來(lái)生成字符串?dāng)?shù)組的代碼
- asp.net通過(guò)js實(shí)現(xiàn)Cookie創(chuàng)建以及清除Cookie數(shù)組的代碼
- asp.net 數(shù)組中字符串替換的幾種方式
- vb.net 數(shù)組參與SQL語(yǔ)句的查詢(xún)范例
- ASP.NET MVC數(shù)組模型綁定詳解
- .NET數(shù)組使用中的注意事項(xiàng)小結(jié)
- .NET下模擬數(shù)組越界的方法詳解
相關(guān)文章
使用HtmlAgilityPack XPath 表達(dá)式抓取博客園數(shù)據(jù)的實(shí)現(xiàn)代碼
使用HtmlAgilityPack XPath表達(dá)式來(lái)抓取博客園數(shù)據(jù)使用WebClient 下載數(shù)據(jù),HtmlAgilityPack XPath表達(dá)式解析數(shù)據(jù),并綁定到Repeater控件2011-12-12一天精通asp.net的學(xué)習(xí)經(jīng)驗(yàn)小結(jié)
一天精通asp.net的學(xué)習(xí)經(jīng)驗(yàn)小結(jié)2010-02-02ASP.NET列出數(shù)據(jù)庫(kù)活躍鏈接的方法
這篇文章主要介紹了ASP.NET列出數(shù)據(jù)庫(kù)活躍鏈接的方法,實(shí)例分析了asp.net列出數(shù)據(jù)庫(kù)活躍鏈接的原理與實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-06-06asp.net如何在圖片上加水印文字具體實(shí)現(xiàn)
這篇文章主要介紹了asp.net如何在圖片上加水印文字具體實(shí)現(xiàn),有需要的朋友可以參考一下2013-12-12Visual?Studio?2022?MAUI?NU1105(NETSDK1005)?問(wèn)題處理記錄
某一天修改了幾行代碼后,突然項(xiàng)目無(wú)法編譯了,提示NU1105錯(cuò)誤,這篇文章主要介紹了Visual?Studio?2022?MAUI?NU1105(NETSDK1005)?處理記錄,需要的朋友可以參考下2022-12-12asp.net DbProviderFactory的使用-示例
NET 2.0有一個(gè)抽象工廠模式的典型應(yīng)用:通過(guò)DBProviderFactory 可以對(duì)不同數(shù)據(jù)庫(kù)進(jìn)行操作。2009-11-11