<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>
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;
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有