private static void Main(string[] args) { // Create Book Dictionary. var list = new List <Book> { new Book("The Stand", "Stephen King"), new Book("The Name of the Wind", "Patrick Rothfuss"), new Book("Robinson Crusoe", "Daniel Defoe"), new Book("The Hobbit", "J.R.R. Tolkien") }; ListExample(list); Logging.LineSeparator(); // Create Book Dictionary. var dictionary = new Dictionary <int, Book> { { 0, new Book("The Stand", "Stephen King") }, { 1, new Book("The Name of the Wind", "Patrick Rothfuss") }, { 2, new Book("Robinson Crusoe", "Daniel Defoe") }, { 3, new Book("The Hobbit", "J.R.R. Tolkien") } }; DictionaryExample(dictionary); Logging.LineSeparator(); DictionaryUsingTryGetValueExample(dictionary); Logging.LineSeparator(); // Create Book Dictionary. var improvedDictionary = new ImprovedDictionary <int, Book> { { 0, new Book("The Stand", "Stephen King") }, { 1, new Book("The Name of the Wind", "Patrick Rothfuss") }, { 2, new Book("Robinson Crusoe", "Daniel Defoe") }, { 3, new Book("The Hobbit", "J.R.R. Tolkien") } }; ImprovedDictionaryExample(improvedDictionary); }
private static void ImprovedDictionaryExample(ImprovedDictionary <int, Book> dictionary) { try { // Output current library. Logging.Log(dictionary); // Add line seperator for readability. Logging.LineSeparator(); // Attempt to output element of index equal to count. Logging.Log(dictionary[dictionary.Count]); } catch (System.Collections.Generic.KeyNotFoundException exception) { // Catch KeyNotFoundExceptions. Logging.Log(exception); } catch (Exception exception) { // Catch unexpected Exceptions. Logging.Log(exception, false); } }