国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

ASP.NET數組刪除重復值實現代碼

2024-07-10 13:29:27
字體:
來源:轉載
供稿:網友

在ASP.NET編程中,要想刪除數組的重復值可以使用多種方法代碼實現相同的效果。今天,在某個博客中看到某功能代碼中的一小段代碼很不錯,它就是用來移動數組中相同值的方法,分享給大家

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

1.前臺代碼:

 

 
  1. <html xmlns="http://www.w3.org/1999/xhtml">  
  2. <head runat="server">  
  3. <title>數組刪除重復值</title>  
  4. </head>  
  5. <body>  
  6. <form id="form1" runat="server">  
  7. <div>  
  8. 數組刪除前:  
  9. <asp:Label ID="lblResult1" runat="server"></asp:Label>  
  10. <br />  
  11. 數組刪除后:  
  12. <asp:Label ID="lblResult2" runat="server"></asp:Label>  
  13. </div>  
  14. </form>  
  15. </body>  
  16. </html> 

2.后臺代碼:

 

 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Collections; //引用  
  8.  
  9. public partial class NetObjects_數組_刪除重復值 : System.Web.UI.Page  
  10. {  
  11. protected void Page_Load(object sender, EventArgs e)  
  12. {  
  13. string strNum = "168,145,150,148,333,888,666,168,144";  
  14. //輸出原數組  
  15. lblResult1.Text = strNum;  
  16. string[] arrNum = strNum.Split(',');  
  17. ArrayList al = new ArrayList();  
  18. for (int i = 0; i < arrNum.Length; i++)  
  19. {  
  20. //判斷數組值是否已經存在  
  21. if (al.Contains(arrNum[i]) == false)  
  22. {  
  23. al.Add(arrNum[i]);  
  24. }  
  25. }  
  26. //把ArrayList轉換數組  
  27. arrNum = new string[al.Count];  
  28. arrNum = (string[])al.ToArray(typeof(string));  
  29. //輸出刪除后數組  
  30. string result = "";  
  31. for (int j = 0; j < arrNum.Length; j++)  
  32. {  
  33. if (j != 0)  
  34. {  
  35. result += ",";  
  36. }  
  37. result += arrNum[j];  
  38. }  
  39. lblResult2.Text = result;  
  40. }  

3.最終輸出效果:

ASP.NET數組刪除重復值實現代碼

以上就是關于ASP.NET數組刪除重復值的實現方法,希望對大家的學習有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 清涧县| 克什克腾旗| 辽源市| 漳州市| 都兰县| 沅陵县| 许昌县| 华宁县| 哈密市| 海宁市| 公安县| 潮州市| 湖北省| 静宁县| 淮安市| 通州区| 凤冈县| 胶南市| 通河县| 琼结县| 启东市| 双流县| 平陆县| 梅河口市| 厦门市| 桐梓县| 贵港市| 登封市| 海口市| 砚山县| 渝北区| 台前县| 清苑县| 犍为县| 杭锦后旗| 拜城县| 灵山县| 紫阳县| 博爱县| 晋宁县| 曲松县|