ASP.NET数组删除重复值实现代码

2025-05-29 0 69

根据这段代码,自己编写了一个小程序作为代码资料参考,方便以后可以直接拿来用,不需要网上找。如果你觉得还不错的话,就把它收藏起来吧!

1.前台代码:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16
<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.后台代码:

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41
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数组删除重复值的实现方法,希望对大家的学习有所帮助。

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

快网idc优惠网 建站教程 ASP.NET数组删除重复值实现代码 https://www.kuaiidc.com/101553.html

相关文章

发表评论
暂无评论