博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

字符串数组去掉重复值方法

Posted on 2008-12-14 20:02  艾新  阅读(691)  评论(1编辑  收藏  举报

using System;
using System.Collections;
using System.Collections.Specialized;
namespace test
{
    class myTest
    {
        static void Main()
        {

            string[] arrInt = new string[] { "1", "1", "2", "3", "4", "33", "4", "66", "77", "2", "44", "33" };
            ArrayList arr = new ArrayList();
            foreach (string i in arrInt)
            {
                if (arr.IndexOf(i) < 0)
                {
                    arr.Add(i);
                   
                }
            }

            //输出测试  
            arrInt = (string[])arr.ToArray(typeof(string));
            foreach (string n in arrInt)
            {
                Console.WriteLine(n);
            }  
        }
    }
}