// Constructor with a MyDictionary object parameter. public MyDictionary(MyDictionary <K, T> dic) { Table = new DicPoint <K, T> [dic.Table.Length]; for (int i = 0; i < dic.Table.Length; i++) { this.Table[i] = dic.Table[i]; } this.Keys = new K[dic.Keys.Length]; for (int i = 0; i < dic.Keys.Length; i++) { this.Keys[i] = dic.Keys[i]; } this.Values = new T[dic.Values.Length]; for (int i = 0; i < dic.Values.Length; i++) { this.Values[i] = dic.Values[i]; } Capacity = dic.capacity; Count = dic.count; }
public MyNewDictionary(MyDictionary <K, T> myDictionary) : base(myDictionary) { }
// Function to clear the dictionary. public static void ClearDic(ref MyDictionary <int, State> myDictionary) { myDictionary.Clear(); Console.WriteLine("The dictionary is clear now!\nPress ENTER to continue"); Console.ReadLine(); }
public static void Demonstrate() { Console.Clear(); //Console.Write((int)'A' + " " + (int)'Z' + " " + (int)'a' + " " + (int)'z'); // Getting the capacity from the user. int capacity = CapacityInput(); // Creating a dictionary with the set capacity. MyDictionary <int, State> myDictionary = new MyDictionary <int, State>(capacity); Console.WriteLine("An empty dictionary with the capacity of {0} has been successfully created!\n", capacity); int choice; do { //Console.Clear(); Console.WriteLine(@"Choose one of the options: 1. Fill the dictionary with random elements. 2. Show the dictionary. 3. Check if there is an element with the wanted key. 4. Check if there is an element with the wanted value. 5. Add an element. 6. Clear the dictionary. 7. Clone the dictionary. 8. Remove an element with the wanted value. 9. Back."); choice = ChoiceInput(9); switch (choice) { case 1: FillDic(ref myDictionary); break; case 2: ShowDic(myDictionary); break; case 3: CheckKey(myDictionary); break; case 4: CheckValue(myDictionary); break; case 5: AddElem(ref myDictionary); break; case 6: ClearDic(ref myDictionary); break; case 7: CloneDic(myDictionary); break; case 8: RemoveFromDic(ref myDictionary); break; } Console.Clear(); } while (choice != 9); }
public static void EventsDemo() { Console.Clear(); // The first collection. MyNewDictionary <int, State> dic1 = new MyNewDictionary <int, State>(); MyDictionary <int, State> buf = new MyDictionary <int, State>(4); MyDicDemo.FillDic(ref buf); dic1 = new MyNewDictionary <int, State>(buf); dic1.Name = "dic1"; // The second collection. MyNewDictionary <int, State> dic2 = new MyNewDictionary <int, State>(4); buf = new MyDictionary <int, State>(4); MyDicDemo.FillDic(ref buf); dic2 = new MyNewDictionary <int, State>(buf); dic2.Name = "dic2"; // The first journal. Journal journal1 = new Journal(); // The second journal. Journal journal2 = new Journal(); // Subscription of the first journal. dic1.CollectionCountChanged += new CollectionHandler(journal1.CollectionCountChanged); dic1.CollectionReferenceChanged += new CollectionHandler(journal1.CollectionReferenceChanged); // Subscription of the second journal. dic1.CollectionReferenceChanged += new CollectionHandler(journal2.CollectionReferenceChanged); dic2.CollectionReferenceChanged += new CollectionHandler(journal2.CollectionReferenceChanged); // Generating a random state object. State rnd = MyDicDemo.RandomState(); // Adding the elem to the 1st collection. dic1.Add(rnd.Name.Length, rnd); // Removing an object from the 1st collection. dic1.Remove(0); // Changing a value int the 1st collection. dic1.Remove(rnd); DicPoint <int, State> dicPointBuf = new DicPoint <int, State>(rnd.Name.Length, rnd); dic1[0] = dicPointBuf; // Adding the elem to the 2nd collection. dic2.Add(rnd.Name.Length, rnd); // Removing an object from the 2nd collection. dic2.Remove(0); // Changing a value int the 2nd collection. dic2.Remove(rnd); dicPointBuf = new DicPoint <int, State>(rnd.Name.Length, rnd); dic2[0] = dicPointBuf; Console.WriteLine(journal1.ToString()); Console.WriteLine(journal2.ToString()); Console.WriteLine("Press ENTER to continue"); Console.ReadLine(); }
// Clone the dictionary. public MyDictionary <K, T> Clone() { MyDictionary <K, T> buf = this; return(buf); }