static void Main() { Phone phone = new Phone(); string line; using (StreamReader reader = new StreamReader(@"..\..\phones.txt")) { while ((line = reader.ReadLine()) != null) { string[] content = line.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries); PhoneEntry pe = new PhoneEntry(content[0].Trim(), content[1].Trim(), content[2]); phone.Add(pe.Name, pe); } } var searchByName = phone.Find("Mimi Shmatkata"); foreach (var value in searchByName) { Console.WriteLine("{0} | {1} | {2}", value.Name, value.City, value.Number); } var searchByNameAndCity = phone.Find("Mimi Shmatkata", "Varna"); foreach (var value in searchByNameAndCity) { Console.WriteLine("{0} | {1} | {2}", value.Name, value.City, value.Number); } }
public PhoneEntry[] ListEntries(int start, int num) { if (start < 0 || start + num > this.entries.Count) { throw new ArgumentOutOfRangeException("Invalid start index or count."); } this.entries.Sort(); PhoneEntry[] ent = new PhoneEntry[num]; for (int i = start; i <= start + num - 1; i++) { PhoneEntry entry = this.entries[i]; ent[i - start] = entry; } return ent; }
public PhoneEntry[] ListEntries(int start, int num) { if (start < 0 || start + num > this.entries.Count) { throw new ArgumentOutOfRangeException("Invalid start index or count."); } this.entries.Sort(); PhoneEntry[] ent = new PhoneEntry[num]; for (int i = start; i <= start + num - 1; i++) { PhoneEntry entry = this.entries[i]; ent[i - start] = entry; } return(ent); }
public PhoneEntry[] ListEntries(int first, int num) { if (first < 0 || first + num > this.dict.Count) { throw new ArgumentOutOfRangeException(); } PhoneEntry[] list = new PhoneEntry[num]; for (int i = first; i <= first + num - 1; i++) { PhoneEntry entry = this.sorted[i]; list[i - first] = entry; } return(list); }
public PhoneEntry[] ListEntries(int first, int num) { if (first < 0 || first + num > this.dict.Count) { throw new ArgumentOutOfRangeException(); } PhoneEntry[] list = new PhoneEntry[num]; for (int i = first; i <= first + num - 1; i++) { PhoneEntry entry = this.sorted[i]; list[i - first] = entry; } return list; }
public bool AddPhone(string name, IEnumerable<string> nums) { string name2 = name.ToLowerInvariant(); PhoneEntry entry; bool flag = !this.dict.TryGetValue(name2, out entry); if (flag) { entry = new PhoneEntry(); entry.Name = name; entry.PhoneNumbers = new SortedSet<string>(); this.dict.Add(name2, entry); this.sorted.Add(entry); } foreach (var num in nums) { this.multidict.Add(num, entry); } entry.PhoneNumbers.UnionWith(nums); return flag; }
public PhoneEntry[] ListEntries(int startIndex, int count) { if (startIndex < 0 || startIndex + count > this.repository.Count) { throw new ArgumentOutOfRangeException("Invalid range"); } var selectedEntries = new PhoneEntry[count]; for (var i = startIndex; i < startIndex + count; i++) { var entry = this.repository[i]; selectedEntries[i - startIndex] = entry; } return selectedEntries; }
public bool AddPhone(string name, IEnumerable <string> nums) { string name2 = name.ToLowerInvariant(); PhoneEntry entry; bool flag = !this.dict.TryGetValue(name2, out entry); if (flag) { entry = new PhoneEntry(); entry.Name = name; entry.PhoneNumbers = new SortedSet <string>(); this.dict.Add(name2, entry); this.sorted.Add(entry); } foreach (var num in nums) { this.multidict.Add(num, entry); } entry.PhoneNumbers.UnionWith(nums); return(flag); }
public bool AddPhone(string name, IEnumerable<string> phoneNumbers) { var nameLowerCase = name.ToLowerInvariant(); PhoneEntry entry; var isPhoneAdded = !this.repositoryByName.TryGetValue(nameLowerCase, out entry); if (isPhoneAdded) { entry = new PhoneEntry { Name = name, PhonesPerName = new SortedSet<string>() }; this.repositoryByName.Add(nameLowerCase, entry); this.repository.Add(entry); } foreach (var num in phoneNumbers) { this.repositoryByPhoneNumber.Add(num, entry); } entry.PhonesPerName.UnionWith(phoneNumbers); return isPhoneAdded; }
public bool AddPhone(string name, IEnumerable <string> nums) { var old = from e in this.entries where e.Name.ToLowerInvariant() == name.ToLowerInvariant() select e; bool flag; if (old.Count() == 0) { PhoneEntry obj = new PhoneEntry(); obj.Name = name; obj.PhoneNumbers = new SortedSet <string>(); foreach (var num in nums) { obj.PhoneNumbers.Add(num); } this.entries.Add(obj); flag = true; } else if (old.Count() == 1) { PhoneEntry obj2 = old.First(); foreach (var num in nums) { obj2.PhoneNumbers.Add(num); } flag = false; } else { Console.WriteLine("Duplicated name in the phonebook found: " + name); return(false); } return(flag); }
public bool AddPhone(string name, IEnumerable<string> nums) { var old = from e in this.entries where e.Name.ToLowerInvariant() == name.ToLowerInvariant() select e; bool flag; if (old.Count() == 0) { PhoneEntry obj = new PhoneEntry(); obj.Name = name; obj.PhoneNumbers = new SortedSet<string>(); foreach (var num in nums) { obj.PhoneNumbers.Add(num); } this.entries.Add(obj); flag = true; } else if (old.Count() == 1) { PhoneEntry obj2 = old.First(); foreach (var num in nums) { obj2.PhoneNumbers.Add(num); } flag = false; } else { Console.WriteLine("Duplicated name in the phonebook found: " + name); return false; } return flag; }
private static void CreateEntry(List<PhoneEntry> phoneEntries, string[] entryData, string[] names) { if (names.Length == 3) { PhoneEntry phoneEntry = new PhoneEntry(names[0].Trim(), entryData[1].Trim(), entryData[2].Trim(), names[2].Trim(), names[1].Trim()); phoneEntries.Add(phoneEntry); } else if (names.Length == 2) { PhoneEntry phoneEntry = new PhoneEntry(names[0].Trim(), entryData[1].Trim(), entryData[2].Trim(), names[1].Trim()); phoneEntries.Add(phoneEntry); } else { PhoneEntry phoneEntry = new PhoneEntry(names[0].Trim(), entryData[1].Trim(), entryData[2].Trim()); phoneEntries.Add(phoneEntry); } }
public void Add(string key, PhoneEntry value) { names.Add(key, value); }