public void SortData() { Console.WriteLine("무엇을 기준으로 정렬하시겠습니까?"); Console.WriteLine("1. 이름 | 2. 전화번호"); int answer = int.Parse(Console.ReadLine()); PhoneInfo[] infoStorage2 = new PhoneInfo[curCnt]; Array.Copy(infoStorage, infoStorage2, curCnt); if (answer == 1) { PhonenameComparer nameComparer = new PhonenameComparer(); Array.Sort(infoStorage2, nameComparer); foreach (PhoneInfo x in infoStorage2) { Console.WriteLine(x.ToString()); } } else if (answer == 2) { PhonenameComparer nameComparer = new PhonenameComparer(); Array.Sort(infoStorage2, nameComparer); foreach (PhoneInfo x in infoStorage2) { Console.WriteLine(x.ToString()); } } else { Console.WriteLine("다른 값을 입력하셨습니다."); } }
public int Compare(object x, object y) { PhoneInfo first = x as PhoneInfo; PhoneInfo second = y as PhoneInfo; if (first.Name.CompareTo(second.Name) == 1) { return(1); } else if (first.Name.CompareTo(second.Name) == -1) { return(-1); } else { return(0); } }
public void InputData() { Console.Write("이름: "); string name = Console.ReadLine().Trim(); //if (name == "") or if (name.Length < 1) or if (name.Equals("")) if (string.IsNullOrEmpty(name)) { Console.WriteLine("이름은 필수입력입니다"); return; } else { int dataIdx = SearchName(name); if (dataIdx > -1) { Console.WriteLine("이미 등록된 이름입니다. 다른 이름으로 입력하세요"); return; } } Console.Write("전화번호: "); string phone = Console.ReadLine().Trim(); if (string.IsNullOrEmpty(phone)) { Console.WriteLine("전화번호는 필수입력입니다"); return; } Console.Write("생일: "); string birth = Console.ReadLine().Trim(); if (birth.Length < 1) { infoStorage[curCnt++] = new PhoneInfo(name, phone); } else { infoStorage[curCnt++] = new PhoneInfo(name, phone, birth); } }