ASP.NET数组删除重复值实现代码
2015-10-10 00:00
801 查看
根据这段代码,自己编写了一个小程序作为代码资料参考,方便以后可以直接拿来用,不需要网上找。如果你觉得还不错的话,就把它收藏起来吧!
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数组删除重复值的实现方法,希望对大家的学习有所帮助。
相关文章推荐
- ASP.NET中readonly与const的区别详解
- ASP.NET中MVC传递数据的几种形式总结
- ASP.NET本调试下配置Web.config识别json
- ASP注入
- ASP注入
- Microsoft.AspNet.FriendlyUrls发布到IIS后404报错的解决方案
- MVC3 之asp.net 与vb.net 互转练习
- asp.net mvc web api 可跨域方法
- ASP.NET动态网站制作(8)-- JS(3)
- ASP.NET多线程编程
- ASP.NET 4.0尚未在 Web 服务器上注册 解决方法
- Raspberry pi 2 OSMC 安装
- asp.net中怎样调用存储过程和存储过程的写法(转载,留着自己看)
- 【翻译】了解ASP.NET MVC的HTML助手
- 使用Areas分离ASP.NET MVC项目
- Asp.net MVC23 使用Areas功能的常见错误
- asp.net检测是否为移动设备
- ASP.NET MVC3 Areas 分离项目 同名控制器(同名Controller) 演示demo
- (读书笔记)Asp.net Mvc 与WebForm 混合开发
- Asp.Net MVC 路由