public int Compare(object x, object y)
        {
            PhoneInfo first = (PhoneInfo)x;
            PhoneInfo other = (PhoneInfo)y;

            return(first.Phone.CompareTo(other.Phone));
        }
Ejemplo n.º 2
0
        public void SortData()
        {
            int choice;

            while (true)
            {
                try
                {
                    Console.WriteLine("1.이름 ASC  2.이름 DESC  3.전화번호 ASC  4.전화번호 DESC");
                    Console.Write("선택 >> ");

                    if (int.TryParse(Console.ReadLine(), out choice))
                    {
                        if (choice < 1 || choice > 4)
                        {
                            throw new MenuChoiceException(choice);

                            //Console.WriteLine("1.이름 ASC  2.이름 DESC  3.전화번호 ASC  4.전화번호 DESC 중에 선택하십시오.");
                            //return;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                catch (MenuChoiceException err)
                {
                    err.ShowWrongChoice();
                }
            }

            PhoneInfo[] new_arr = new PhoneInfo[curCnt];
            Array.Copy(infoStorage, new_arr, curCnt);

            if (choice == 1)
            {
                Array.Sort(new_arr, new NameComparator());
            }
            else if (choice == 2)
            {
                Array.Sort(new_arr, new NameComparator());
                Array.Reverse(new_arr);
            }
            else if (choice == 3)
            {
                Array.Sort(new_arr, new PhoneComparator());
            }
            else if (choice == 4)
            {
                Array.Sort(new_arr, new PhoneComparator());
                Array.Reverse(new_arr);
            }

            for (int i = 0; i < curCnt; i++)
            {
                Console.WriteLine(new_arr[i].ToString());
            }
        }
Ejemplo n.º 3
0
        public int CompareTo(object obj)
        {
            PhoneInfo other = (PhoneInfo)obj;

            return(this.name.CompareTo(other.name));

            //if (this.name.CompareTo(other.name) == 1)
            //    return 1;
            //else if (this.name.CompareTo(other.name) == -1)
            //    return -1;
            //else
            //    return 0;
        }
Ejemplo n.º 4
0
        public void InputData()
        {
            Console.WriteLine("1.일반  2.대학  3.회사");
            Console.Write("선택 >> ");
            int choice;

            while (true)
            {
                if (int.TryParse(Console.ReadLine(), out choice))
                {
                    break;
                }
            }
            if (choice < 1 || choice > 3)
            {
                Console.WriteLine("1.일반  2.대학  3.회사 중에 선택하십시오.");
                return;
            }

            PhoneInfo info = null;

            switch (choice)
            {
            case 1:
                info = InputFriendInfo();
                break;

            case 2:
                info = InputUnivInfo();
                break;

            case 3:
                info = InputCompanyInfo();
                break;
            }
            if (info != null)
            {
                infoStorage[curCnt++] = info;
                Console.WriteLine("데이터 입력이 완료되었습니다");
            }
        }