Posted
Filed under C#
[원문] - http://firstpolaris.tistory.com/?page=7

private
string[] ArrayDistinct(string[] source)

        {

            // generic버전

            //List<string> temp = new List<string>();

            //temp.AddRange(source);

            //IEnumerable<string> distinct = temp.Distinct();

            //return distinct.ToArray<string>();

 

            // .. 버전

            string destination = string.Empty;//임시 필드

            // 중복제거

            for (int i = 0; i < source.Length; i++)

            {

                for (int j = 0; j < source.Length; j++)

                {

                    if (source[i] == source[j] && i != j) source[j] = string.Empty;

                }

            }

 

            // ,를 구분자로 문자열 생성

            for (int i = 0; i < source.Length; i++)

            {

                if (!source[i].Equals(string.Empty)) destination += source[i] + ",";

            }

 

            // 마지막에 붙은 ,하나 제거

            destination = destination.Substring(0, destination.Length - 1);


            return destination.Split(',');

 

        }

2010/10/08 15:43 2010/10/08 15:43