public static void Main() { string decorationLine = new string('-', Console.WindowWidth); Console.Write(decorationLine); Console.WriteLine("***Presenting the functionality of the data structure 'BiDictionary' - allows"); Console.WriteLine("adding values by two keys, searching by a single key or by both keys and"); Console.WriteLine("removing values by both keys***"); Console.Write(decorationLine); BiDictionary<string, string, Person> peopleDictionary = new BiDictionary<string, string, Person>(); Console.WriteLine("---Test add operation---"); foreach (Person person in people) { peopleDictionary.Add(person.FirstName, person.LastName, person); } Console.WriteLine("Count after addition: {0}", peopleDictionary.Count); Console.WriteLine(); Console.WriteLine("---Test get values by first key---"); string firstName = "Gosho"; Console.WriteLine("All people with first name '{0}' are:", firstName); PrintPeopleOnConsole(peopleDictionary.GetByFirstKey(firstName)); Console.WriteLine(); Console.WriteLine("---Test get values by second key---"); string lastName = "Peshov"; Console.WriteLine("All people with last name '{0}' are:", lastName); PrintPeopleOnConsole(peopleDictionary.GetBySecondKey(lastName)); Console.WriteLine(); Console.WriteLine("---Test get values by first key and second key---"); string firstKey = "Gosho"; string secondKey = "Goshov"; Console.WriteLine("All people with first name '{0}' and last name '{1}' are:", firstKey, secondKey); PrintPeopleOnConsole(peopleDictionary.GetByBothKeys(firstKey, secondKey)); Console.WriteLine(); Console.WriteLine("---Test remove operation---"); Console.WriteLine("Removing all people with first key '{0}' and second key '{1}'", firstKey, secondKey); peopleDictionary.Remove(firstKey, secondKey); Console.WriteLine("Count of people after removal: {0}", peopleDictionary.Count); Console.WriteLine("Count of people with first name '{0}' after removal: {1}", firstKey, peopleDictionary.GetByFirstKey(firstKey).Count); Console.WriteLine("Count of people with last name '{0}' after removal: {1}", secondKey, peopleDictionary.GetBySecondKey(secondKey).Count); Console.WriteLine(); Console.WriteLine("---Test clear operation---"); peopleDictionary.Clear(); Console.WriteLine("Count of people after clearing the dictionary: {0}", peopleDictionary.Count); }
public static void Main(string[] args) { BiDictionary <int, string, decimal> biDictionary = FillBiDictionary(); decimal[] searchByKey1 = biDictionary.GetByKey1(5).Take(20).ToArray <decimal>(); Console.WriteLine("Values searched by key1:"); PrintValuesCollection(searchByKey1); decimal[] searchByKey2 = biDictionary.GetByKey2("key2:" + 13).Take(20).ToArray <decimal>(); Console.WriteLine(new string('*', 20)); Console.WriteLine("Values searched by key2:"); PrintValuesCollection(searchByKey2); decimal[] searchByBothKeys = biDictionary.GetByBothKeys(5, "key2:" + 13).Take(20).ToArray <decimal>(); Console.WriteLine(new string('*', 20)); Console.WriteLine("Values searched by both keys:"); PrintValuesCollection(searchByBothKeys); }