荣耀之链论坛

 找回密码
 立即注册
搜索
查看: 4220|回复: 0

List<>去重

[复制链接]

1374

主题

2504

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10697
发表于 2014-8-28 21:53 | 显示全部楼层 |阅读模式
private void button1_Click(object sender, EventArgs e)
        {
            List<string> strl = new List<string>();
            strl.Add("a");
            strl.Add("a");
            strl.Add("a");
            strl.Add("a");
            strl.Add("a");
            strl.Add("a");
            strl.Add("a");
            for (int i = 0; i < strl.Count; i++)
            {
                for (int t = 0; t < strl.Count-1-i; t++)
                {
                    //MessageBox.Show("i=" + i.ToString() + "    t=" + t.ToString());
                    if (strl[i] == strl[t+i+1])
                    {
                        //MessageBox.Show("it" + i.ToString() + t.ToString() + "shanchule     " + strl[t + i + 1]);
                        strl.RemoveAt(t + i + 1);
                        t--;
                        //strl_rm.Add(strl[t + i + 1]);
                    }
                }
            }

            
            for (int i = 0; i < strl.Count; i++)
            {
                MessageBox.Show(strl[i]);
            }
        }

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

荣耀之链

GMT+8, 2025-9-10 23:00 , Processed in 0.013390 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表