public bool SettingsEqual(ISettingsObject obj) { ColumnWidths other = obj as ColumnWidths; if (other == null) { return(false); } if (m_columns.Count != other.m_columns.Count) { return(false); } IDictionaryEnumerator enumerator = m_columns.GetEnumerator(); while (enumerator.MoveNext()) { object otherValue = other.m_columns[enumerator.Key]; if (otherValue == null || (int)enumerator.Value != (int)otherValue) { return(false); } } return(true); }
/// <summary> /// Retrieve a class from the cache /// </summary> /// <param name="package"></param> /// <param name="name"></param> /// <returns></returns> public ClassModel Resolve(string package, string name) { if (!IsValid) { return(ClassModel.VoidClass); } // IDictionaryEnumerator eFiles = Files.GetEnumerator(); FileModel aFile; while (eFiles.MoveNext()) { aFile = eFiles.Value as FileModel; if (aFile.Package == package) { foreach (ClassModel aClass in aFile.Classes) { if (aClass.ClassName == name) { return(aClass); } } } } return(ClassModel.VoidClass); }
IEnumerator <KeyValuePair <string, object> > IEnumerable <KeyValuePair <string, object> > .GetEnumerator() { if (Disposed) { throw new ObjectDisposedException("DBResourceReader object is already disposed."); } return(_resourceDictionary.GetEnumerator() as IEnumerator <KeyValuePair <string, object> >); }
public IDictionaryEnumerator GetEnumerator() { Debug.WriteLine("DBResourceReader.GetEnumerator()"); // NOTE: this is the only enumerator called by the runtime for // implicit expressions if (Disposed) { throw new ObjectDisposedException("DBResourceReader object is already disposed."); } return(_resourceDictionary.GetEnumerator()); }
public static void GetEnumeratorTest(ListDictionary ld, KeyValuePair <string, string>[] data) { bool repeat = true; IDictionaryEnumerator enumerator = ld.GetEnumerator(); Assert.NotNull(enumerator); while (repeat) { Assert.Throws <InvalidOperationException>(() => enumerator.Current); foreach (KeyValuePair <string, string> element in data) { Assert.True(enumerator.MoveNext()); DictionaryEntry entry = (DictionaryEntry)enumerator.Current; Assert.Equal(entry, enumerator.Current); Assert.Equal(element.Key, entry.Key); Assert.Equal(element.Value, entry.Value); Assert.Equal(element.Key, enumerator.Key); Assert.Equal(element.Value, enumerator.Value); } Assert.False(enumerator.MoveNext()); Assert.Throws <InvalidOperationException>(() => enumerator.Current); Assert.False(enumerator.MoveNext()); enumerator.Reset(); enumerator.Reset(); repeat = false; } }
IEnumerator LoadQueueCoroutine() { while (loadQueue.Count > 0) { ListDictionary <string, System.Action <Object> > .Enumerator e = loadQueue.GetEnumerator(); if (e.MoveNext()) { KeyValuePair <string, List <System.Action <Object> > > kv = e.Current; Object o = LoadResource(kv.Key, kv.Value.Count); foreach (System.Action <Object> loadCompleteDelegate in kv.Value) { loadCompleteDelegate(o); } yield return(null); loadQueue.Remove(kv.Key); } else { Debug.LogError("WTF"); } // yield return null; } }
private void BasicTests(ListDictionary ld) { Assert.AreEqual(0, ld.Count, "Count"); Assert.IsFalse(ld.IsFixedSize, "IsFixedSize"); Assert.IsFalse(ld.IsReadOnly, "IsReadOnly"); Assert.IsFalse(ld.IsSynchronized, "IsSynchronized"); Assert.AreEqual(0, ld.Keys.Count, "Keys"); Assert.AreEqual(0, ld.Values.Count, "Values"); Assert.IsNotNull(ld.SyncRoot, "SyncRoot"); Assert.IsNotNull(ld.GetEnumerator(), "GetEnumerator"); Assert.IsNotNull((ld as IEnumerable).GetEnumerator(), "IEnumerable.GetEnumerator"); ld.Add("a", "1"); Assert.AreEqual(1, ld.Count, "Count-1"); Assert.IsTrue(ld.Contains("a"), "Contains(a)"); Assert.IsFalse(ld.Contains("1"), "Contains(1)"); ld.Add("b", null); Assert.AreEqual(2, ld.Count, "Count-2"); Assert.IsNull(ld["b"], "this[b]"); DictionaryEntry[] entries = new DictionaryEntry[2]; ld.CopyTo(entries, 0); ld["b"] = "2"; Assert.AreEqual("2", ld["b"], "this[b]2"); ld.Remove("b"); Assert.AreEqual(1, ld.Count, "Count-3"); ld.Clear(); Assert.AreEqual(0, ld.Count, "Count-4"); }
/// <summary> /// This function will retrieve an element from a linked list data structure /// The requirements were to search the list in one pass, and retrieve an /// element a certain number of entries from the end of the list. /// I chose to use a .NET queue data structure to store the elements so /// that I would have easy access to the required data element at the end /// of the list. /// Cases that could occur. /// 1) The size of the linked list is too small to find the correct entry /// 2) The list is large enough and we should retrieve the element. /// Note: **** /// I assumed here that we should search through the list without using /// some of the nicer .NET features. I could have used the .Count property /// of the ListDictionary, which would have made it much easier to access the /// correct element. /// I will supply an implementation that uses some of the .NET features /// of this data structure as well. /// </summary> /// <param name="ElementIndexFromEnd">1 based index from the end /// of the list. 1 here would select the last element in the list.</param> /// <returns>Data element from the linked list that is the /// ElementIndexFromEnd entry </returns> private Int32 RetrieveData(Int32 ElementIndexFromEnd) { if (ElementIndexFromEnd <= 0) { throw new Exception ("Invalid selected index. Index was " + ElementIndexFromEnd.ToString()); } // Keep track of the size of the list Int32 ListSize = 0; DictionaryEntry Dict; // Data element retrieved from the linked list Int32 Data = 0; // Flag to know when we successfully retrieved a data element from the list bool Success; // Data structure to store the last items from the list Queue Q = new Queue(); // Initialize the linked list enumerator for accessing the list IDictionaryEnumerator Enum = m_List.GetEnumerator(); Enum.Reset(); Enum.MoveNext(); // Cycle through all elements of the list // List size will be the number of entries in the list at the end // of the do loop. do { Dict = (DictionaryEntry)Enum.Current; Data = (Int32)Dict.Value; Q.Enqueue(Data); /* If we have stored one more than the required number of * elements from the end, remove an element from the queue */ if (Q.Count == ElementIndexFromEnd + 1) { Q.Dequeue(); } Success = Enum.MoveNext(); ListSize++; }while (Success); /* Check to see if the linked list was long enough so that we can * retrieve the correct element from the list. */ if (ListSize >= ElementIndexFromEnd) { // Get correct data item from the .NET queue Int32 RetData = (Int32)Q.Dequeue(); // Push the data to a Windows form text box. this.tbRetVal.Text = RetData.ToString(); return(RetData); } else { throw new Exception("List size was not long enough"); } }
static void Main() { ListDictionary listDictionary = new ListDictionary(); listDictionary.Add(1, "Asia"); listDictionary.Add(2, "Australia"); listDictionary.Add(3, "Africa"); listDictionary.Add(4, "America"); listDictionary.Add(5, "Antartica"); Console.WriteLine("Printing the elements"); foreach (DictionaryEntry entry in listDictionary) { Console.WriteLine("{0} = {1}", entry.Key, entry.Value); } bool ld = listDictionary.Contains(8); Console.WriteLine("Contains the key 8 in the list or not:{0}", ld); Console.WriteLine("Printing the element list using GetEnumerator method-----"); IDictionaryEnumerator ide = listDictionary.GetEnumerator(); DictionaryEntry de; while (ide.MoveNext()) { de = (DictionaryEntry)ide.Current; Console.WriteLine("{0} = {1}", de.Key, de.Value); } DictionaryEntry[] arr = new DictionaryEntry[listDictionary.Count]; listDictionary.CopyTo(arr, 0); Console.WriteLine("Printing the Copied Array"); foreach (var arr1 in arr) { Console.WriteLine("{0}-->{1}", arr1.Key, arr1.Value); } listDictionary.Remove(4); Console.WriteLine("List Printing after removing the element from the index 4"); foreach (DictionaryEntry item2 in listDictionary) { Console.WriteLine("{0} --> {1}", item2.Key, item2.Value); } }
/// <summary> /// Sets up the mouse cursor and status bar, according to what is current running. /// </summary> private void VisualizeProcesses() { //ascertain which cursor to display, an arrow, an arrow & hourglass, or hourglass, or an overridden (seized) cursor Cursor newCursor = Cursors.Arrow; if (_seizedCursor == null) { if (_processesDictionary.Count > 0) { newCursor = Cursors.AppStarting; foreach (DictionaryEntry entry in _processesDictionary) { VisualizableProcess process = entry.Value as VisualizableProcess; if (process != null && process.AllowUserInteraction == false) { newCursor = Cursors.WaitCursor; } } } } else { //cursor has been overridden newCursor = _seizedCursor; } Action hack = () => { //display the cursor _owner.Cursor = newCursor; //set the staus bar if (_statusBarPanel != null) { //ascertain the new text string newText = _awaitingText == null ? "" : _awaitingText; System.Collections.IDictionaryEnumerator de = _processesDictionary.GetEnumerator(); if (de.MoveNext()) { VisualizableProcess oldestProcess = de.Value as VisualizableProcess; if (oldestProcess != null) { newText = oldestProcess.Description; } } _statusBarPanel.Text = newText; } }; if (_owner.Visible) { _owner.Invoke(hack); } }
static void Main(string[] args) { ListDictionary ld = new ListDictionary(); ld.Add("sravani", "pdrl"); ld.Add("balu", "guntur"); ld.Add("Appu", "Mum"); ld.Add("Phanii", "pune"); ld.Add("reethu", "eluru"); ld.Add("lucky", "Assam"); foreach (DictionaryEntry item in ld) { Console.WriteLine("{0}--------->{1}", item.Key, item.Value); } Console.WriteLine("-----------------------using count property--------------"); Console.WriteLine("count is: {0}", ld.Count); Console.WriteLine("Is synchrozied or not :{0}", ld.IsSynchronized); Console.WriteLine("is list is fixed size:{0}", ld.IsFixedSize); Console.WriteLine("list is readonly property ?:{0}", ld.IsReadOnly); Console.WriteLine("-----------------get an icollection contain keys------------"); ICollection ic = ld.Keys; foreach (var s in ic) { Console.WriteLine(s); } Console.WriteLine("------------------get an Icollection contain values--------------"); ICollection ic1 = ld.Values; foreach (var s in ic) { Console.WriteLine(s); } Console.WriteLine("-------------------get Enumerator--------------------------------"); IDictionaryEnumerator en = ld.GetEnumerator(); while (en.MoveNext()) { Console.WriteLine(en.Key + " --> " + en.Value); } Console.WriteLine("----------------Checks contains the key---------------------------"); Console.WriteLine(ld.Contains("reethu")); Console.WriteLine("-------------copyTo Method----------------------------------------"); Console.WriteLine("-----------------// with key reethu------------------------------"); Console.WriteLine(ld["reethu"]); Console.WriteLine("----------// Setting the value associated with key balu-----------"); ld["balu"] = "hey babluu"; foreach (DictionaryEntry de in ld) { Console.WriteLine(de.Key + "-------" + de.Value); } }
static void Main() { ListDictionary listDictionary = new ListDictionary(); listDictionary.Add(1, "Aron"); listDictionary.Add(2, "Smith"); listDictionary.Add(3, "Ray"); listDictionary.Add(4, "Todd"); listDictionary.Add(5, "James"); Console.WriteLine("List dictionary items"); foreach (DictionaryEntry de in listDictionary) { Console.WriteLine("{0} = {1}", de.Key, de.Value); } bool bb = listDictionary.Contains(7); Console.WriteLine("Contains the key 7 in the list or not:{0}", bb); Console.WriteLine("Printing the element list using GetEnumerator method-----"); IDictionaryEnumerator ide = listDictionary.GetEnumerator(); DictionaryEntry dde; while (ide.MoveNext()) { dde = (DictionaryEntry)ide.Current; Console.WriteLine("{0} = {1}", dde.Key, dde.Value); } DictionaryEntry[] arr = new DictionaryEntry[listDictionary.Count]; listDictionary.CopyTo(arr, 0); Console.WriteLine("Printing the Copied Array"); foreach (var arr1 in arr) { Console.WriteLine("{0}-->{1}", arr1.Key, arr1.Value); } listDictionary.Remove(4); Console.WriteLine("List Printing after removing the element from the index 4"); foreach (DictionaryEntry item2 in listDictionary) { Console.WriteLine("{0} --> {1}", item2.Key, item2.Value); } }
private void ChangeOver() { IDictionaryEnumerator en = _list.GetEnumerator(); Hashtable newTable; if (_caseInsensitive) { newTable = new Hashtable(InitialHashtableSize, StringComparer.OrdinalIgnoreCase); } else { newTable = new Hashtable(InitialHashtableSize); } while (en.MoveNext()) { newTable.Add(en.Key, en.Value); } // Keep the order of writing to hashtable and list. // We assume we will see the change in hashtable if list is set to null in // this method in another reader thread. _hashtable = newTable; _list = null; }
static void Main(string[] args) { ListDictionary ld = new ListDictionary(); ld.Add("Lucky", "Jakkula"); ld.Add("Micky", "Jakkula"); ld.Add("Likki", "Venna"); foreach (DictionaryEntry item in ld) { Console.WriteLine("{0}=>{1}", item.Key, item.Value); } Console.WriteLine("count = {0}", ld.Count); Console.WriteLine("Is synchrozied:{0}", ld.IsSynchronized); Console.WriteLine(" fixed size:{0}", ld.IsFixedSize); Console.WriteLine("is readonly :{0}", ld.IsReadOnly); Console.WriteLine("-----------------Only keys------------"); ICollection ic = ld.Keys; foreach (var s in ic) { Console.WriteLine(s); } Console.WriteLine("------------------Only values--------------"); ICollection ic1 = ld.Values; foreach (var s in ic) { Console.WriteLine(s); } Console.WriteLine("---------------get Enumerator-------------"); IDictionaryEnumerator en = ld.GetEnumerator(); while (en.MoveNext()) { Console.WriteLine(en.Key + " --> " + en.Value); } Console.WriteLine("----------------contains the key-------------------"); Console.WriteLine(ld.Contains("Likki")); Console.WriteLine("-------------copyTo Method------------------------------"); Console.WriteLine(ld["Micky"]); ld["Likitha"] = "Raj"; foreach (DictionaryEntry de in ld) { Console.WriteLine($"{de.Key}=>{de.Value}"); } Console.ReadLine(); }
public IEnumerable <DbColumn[]> DbListValues() { IDictionaryEnumerator itr = properties.GetEnumerator(); while (itr.MoveNext()) { byte datatype = DataTypeSerializer.Serialize(itr.Value); yield return (new[] { new DbColumn("name", itr.Key, DbType.String), new DbColumn("value", itr.Value, DbType.String), new DbColumn("datatype", datatype, DbType.Byte) }); } }
internal void Remove(Filter filter) { Type key = null; IDictionaryEnumerator enumerator = dictionary.GetEnumerator(); while (enumerator.MoveNext()) { if (enumerator.Value == filter) { key = (Type)enumerator.Key; break; } } if (key != null) { dictionary.Remove(key); } }
public static void GetEnumerator_ModifiedCollectionTest(ListDictionary ld, KeyValuePair <string, string>[] data) { IDictionaryEnumerator enumerator = ld.GetEnumerator(); Assert.NotNull(enumerator); if (data.Length > 0) { Assert.True(enumerator.MoveNext()); DictionaryEntry current = (DictionaryEntry)enumerator.Current; ld.Remove("key"); Assert.Equal(current, enumerator.Current); Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext()); Assert.Throws <InvalidOperationException>(() => enumerator.Reset()); } else { ld.Add("newKey", "newValue"); Assert.Throws <InvalidOperationException>(() => enumerator.MoveNext()); } }
public void Test01() { ListDictionary ld; IDictionaryEnumerator en; DictionaryEntry curr; // Eumerator.Current value DictionaryEntry de; // Eumerator.Entry value Object k; // Eumerator.Key value Object v; // Eumerator.Value // simple string values string[] values = { "a", "aa", "", " ", "text", " spaces", "1", "$%^#", "2222222222222222222222222", System.DateTime.Today.ToString(), Int32.MaxValue.ToString() }; // keys for simple string values string[] keys = { "zero", "one", " ", "", "aa", "1", System.DateTime.Today.ToString(), "$%^#", Int32.MaxValue.ToString(), " spaces", "2222222222222222222222222" }; // [] ListDictionary GetEnumerator() //----------------------------------------------------------------- ld = new ListDictionary(); // [] for empty dictionary // en = ld.GetEnumerator(); string type = en.GetType().ToString(); if (type.IndexOf("Enumerator", 0) == 0) { Assert.False(true, string.Format("Error, type is not Enumerator")); } // // MoveNext should return false // bool res = en.MoveNext(); if (res) { Assert.False(true, string.Format("Error, MoveNext returned true")); } // // Attempt to get Current should result in exception // Assert.Throws <InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; }); // // [] for Filled dictionary // for (int i = 0; i < values.Length; i++) { ld.Add(keys[i], values[i]); } en = ld.GetEnumerator(); type = en.GetType().ToString(); if (type.IndexOf("Enumerator", 0) == 0) { Assert.False(true, string.Format("Error, type is not Enumerator")); } // // MoveNext should return true // for (int i = 0; i < ld.Count; i++) { res = en.MoveNext(); if (!res) { Assert.False(true, string.Format("Error, MoveNext returned false", i)); } curr = (DictionaryEntry)en.Current; de = en.Entry; // //enumerator enumerates in different than added order // so we'll check Contains // if (!ld.Contains(curr.Key.ToString())) { Assert.False(true, string.Format("Error, Current dictionary doesn't contain key from enumerator", i)); } if (!ld.Contains(en.Key.ToString())) { Assert.False(true, string.Format("Error, Current dictionary doesn't contain key from enumerator", i)); } if (!ld.Contains(de.Key.ToString())) { Assert.False(true, string.Format("Error, Current dictionary doesn't contain Entry.Key from enumerator", i)); } if (String.Compare(ld[curr.Key.ToString()].ToString(), curr.Value.ToString()) != 0) { Assert.False(true, string.Format("Error, Value for current Key is different in dictionary", i)); } if (String.Compare(ld[de.Key.ToString()].ToString(), de.Value.ToString()) != 0) { Assert.False(true, string.Format("Error, Entry.Value for current Entry.Key is different in dictionary", i)); } if (String.Compare(ld[en.Key.ToString()].ToString(), en.Value.ToString()) != 0) { Assert.False(true, string.Format("Error, En-tor.Value for current En-tor.Key is different in dictionary", i)); } // while we didn't MoveNext, Current should return the same value DictionaryEntry curr1 = (DictionaryEntry)en.Current; if (!curr.Equals(curr1)) { Assert.False(true, string.Format("Error, second call of Current returned different result", i)); } DictionaryEntry de1 = en.Entry; if (!de.Equals(de1)) { Assert.False(true, string.Format("Error, second call of Entry returned different result", i)); } } // next MoveNext should bring us outside of the collection // res = en.MoveNext(); res = en.MoveNext(); if (res) { Assert.False(true, string.Format("Error, MoveNext returned true")); } // // Attempt to get Current should result in exception // Assert.Throws <InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; }); // // Attempt to get Entry should result in exception // Assert.Throws <InvalidOperationException>(() => { de = en.Entry; }); // // Attempt to get Key should result in exception // Assert.Throws <InvalidOperationException>(() => { k = en.Key; }); // // Attempt to get Value should result in exception // Assert.Throws <InvalidOperationException>(() => { v = en.Value; }); en.Reset(); // // Attempt to get Current should result in exception // Assert.Throws <InvalidOperationException>(() => { curr = (DictionaryEntry)en.Current; }); // // Attempt to get Entry should result in exception // Assert.Throws <InvalidOperationException>(() => { de = en.Entry; }); // // [] Modify dictionary when enumerating // if (ld.Count < 1) { for (int i = 0; i < values.Length; i++) { ld.Add(keys[i], values[i]); } } en = ld.GetEnumerator(); res = en.MoveNext(); if (!res) { Assert.False(true, string.Format("Error, MoveNext returned false")); } curr = (DictionaryEntry)en.Current; de = en.Entry; k = en.Key; v = en.Value; int cnt = ld.Count; ld.Remove(keys[0]); if (ld.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove item with 0th key")); } // will return just removed item DictionaryEntry curr2 = (DictionaryEntry)en.Current; if (!curr.Equals(curr2)) { Assert.False(true, string.Format("Error, current returned different value after midification")); } // will return just removed item DictionaryEntry de2 = en.Entry; if (!de.Equals(de2)) { Assert.False(true, string.Format("Error, Entry returned different value after midification")); } // will return just removed item Object k2 = en.Key; if (!k.Equals(k2)) { Assert.False(true, string.Format("Error, Key returned different value after midification")); } // will return just removed item Object v2 = en.Value; if (!v.Equals(v2)) { Assert.False(true, string.Format("Error, Value returned different value after midification")); } // exception expected Assert.Throws <InvalidOperationException>(() => { res = en.MoveNext(); }); // exception expected Assert.Throws <InvalidOperationException>(() => { en.Reset(); }); // // [] Modify dictionary after enumerated beyond the end // ld.Clear(); for (int i = 0; i < values.Length; i++) { ld.Add(keys[i], values[i]); } en = ld.GetEnumerator(); for (int i = 0; i < ld.Count; i++) { en.MoveNext(); } curr = (DictionaryEntry)en.Current; de = en.Entry; k = en.Key; v = en.Value; cnt = ld.Count; ld.Remove(keys[0]); if (ld.Count != cnt - 1) { Assert.False(true, string.Format("Error, didn't remove item with 0th key")); } // will return just removed item DictionaryEntry curr3 = (DictionaryEntry)en.Current; if (!curr.Equals(curr3)) { Assert.False(true, string.Format("Error, current returned different value after midification")); } // will return just removed item de2 = en.Entry; if (!de.Equals(de2)) { Assert.False(true, string.Format("Error, Entry returned different value after midification")); } // will return just removed item k2 = en.Key; if (!k.Equals(k2)) { Assert.False(true, string.Format("Error, Key returned different value after midification")); } // will return just removed item v2 = en.Value; if (!v.Equals(v2)) { Assert.False(true, string.Format("Error, Value returned different value after midification")); } // exception expected Assert.Throws <InvalidOperationException>(() => { res = en.MoveNext(); }); // exception expected Assert.Throws <InvalidOperationException>(() => { en.Reset(); }); ///////////////////////////////////// //// Code coverage // // [] Call IEnumerable.GetEnumerator() // en = ld.GetEnumerator(); IEnumerator en2 = ((IEnumerable)ld).GetEnumerator(); if (en2 == null) { Assert.False(true, string.Format("Error, enumerator was null")); } }
public IDictionaryEnumerator GetMetadataEnumerator() { EnsureResData(); return(_resMetadata.GetEnumerator()); }
static void Main(string[] args) { //Creating a StringCollection named myCol. StringCollection myCol = new StringCollection(); myCol.Add("A"); myCol.Add("B"); myCol.Add("C"); myCol.Add("D"); myCol.Add("E"); myCol.Add("F"); //Taking an enumerator and using GetEnumerator method. //Supports a simple iteration over a StringCollection. StringEnumerator myEnumeration = myCol.GetEnumerator(); //If MoveNext passes the end of the collection, the enumerator is positioned //after the last element in the collection and MoveNext returns false. while (myEnumeration.MoveNext()) { Console.WriteLine(myEnumeration.Current); } //StringDictionary collection enumeration. StringDictionary dict = new StringDictionary(); dict.Add("A", "ABC"); dict.Add("B", "AEC"); dict.Add("C", "AVC"); dict.Add("D", "ADC"); dict.Add("E", "ARC"); //IEnumerator interface supports a simple iteration over a non-generic collection. IEnumerator enumerator = dict.GetEnumerator(); //Defines dictionary key/value pair that can be set or retrieved. DictionaryEntry dictEntry; while (enumerator.MoveNext()) { dictEntry = (DictionaryEntry)enumerator.Current; Console.WriteLine(dictEntry.Key + ":" + dictEntry.Value); } //Creating a Hybrid dictionary HybridDictionary myHybridDict = new HybridDictionary(); //Adding key/value pairs in hybrid dictionary. myHybridDict.Add("I", "first"); myHybridDict.Add("II", "second"); myHybridDict.Add("III", "third"); myHybridDict.Add("IV", "fourth"); myHybridDict.Add("V", "fifth"); //To get an IDictionary enumerator for the hybrid dictionary. IDictionaryEnumerator iDictEnum = myHybridDict.GetEnumerator(); while (iDictEnum.MoveNext()) { Console.WriteLine(iDictEnum.Key + "-->" + iDictEnum.Value); } //Creating a HashTable. Hashtable myHash = new Hashtable(); //Adding key/value pair for hash table. myHash.Add("A", "Apple"); myHash.Add("B", "Banana"); myHash.Add("C", "Custard Apple"); myHash.Add("D", "Dry fruits"); myHash.Add("E", "Eagle"); //To get an IDictionaryEnumerator for Hashtable. IDictionaryEnumerator iDictHash = myHash.GetEnumerator(); while (iDictHash.MoveNext()) { Console.WriteLine(iDictHash.Key + "-->" + iDictHash.Value); } //Creating a ListDictionary ListDictionary myLstDict = new ListDictionary(); myLstDict.Add("India", "New Delhi"); myLstDict.Add("Australia", "Canberra"); myLstDict.Add("Belgium", "Brussels"); myLstDict.Add("Netherland", "Amsterdam"); myLstDict.Add("China", "Beijing"); myLstDict.Add("Russia", "Moscow"); //To get an IDictionaryEnumerator for the ListDictionary. IDictionaryEnumerator iDictEnumLstDict = myLstDict.GetEnumerator(); while (iDictEnumLstDict.MoveNext()) { Console.WriteLine(iDictEnumLstDict.Key + "-->" + iDictEnumLstDict.Value); } //Creating a SortedDictionary. SortedDictionary <string, string> mySortedDict = new SortedDictionary <string, string>(); mySortedDict.Add("India", "New Delhi"); mySortedDict.Add("Australia", "Canberra"); mySortedDict.Add("Belgium", "Brussels"); mySortedDict.Add("Netherland", "Amsterdam"); mySortedDict.Add("China", "Beijing"); mySortedDict.Add("Russia", "Moscow"); //To get an IDictionaryEnumerator for the SortedDictionary. IDictionaryEnumerator iDictEnumerator = mySortedDict.GetEnumerator(); while (iDictEnumerator.MoveNext()) { Console.WriteLine(iDictEnumerator.Key + "-->" + iDictEnumerator.Value); } //Creating a collection of string. Collection <string> myColl = new Collection <string>(); myColl.Add("ABD"); myColl.Add("DEF"); myColl.Add("CFR"); myColl.Add("EVF"); myColl.Add("NBR"); IEnumerator <string> enumColl = myColl.GetEnumerator(); while (enumColl.MoveNext()) { Console.WriteLine(enumColl.Current); } //Creating a Linked list of integers. LinkedList <int> myLinkedList = new LinkedList <int>(); myLinkedList.AddLast(2); myLinkedList.AddLast(21); myLinkedList.AddLast(12); myLinkedList.AddLast(23); myLinkedList.AddLast(32); //To get an enumerator for the List. LinkedList <int> .Enumerator lnkListEnum = myLinkedList.GetEnumerator(); Display(lnkListEnum); //Creating a Hashset<T> of strings. //Initialize a new instance of HashSet<string> class that is empty //and uses the default equality comparer for the set type. HashSet <string> hashset = new HashSet <string>(); hashset.Add("C#"); hashset.Add("Asp.Net"); hashset.Add("SQL Server"); hashset.Add("MVC"); hashset.Add("Angular"); //To get an enumerator for the HashSet<T>. HashSet <string> .Enumerator hashEnum = hashset.GetEnumerator(); DisplayHashSet(hashEnum); Console.ReadKey(); }
public IDictionaryEnumerator GetEnumerator() { _isReaderDirty = true; EnsureResData(); return(_resData.GetEnumerator()); }
public IEnumerator GetEnumerator() { return(carDictionary.GetEnumerator()); }
public static void GetEnumerator_ModifiedCollectionTest(ListDictionary ld, KeyValuePair<string, string>[] data) { IDictionaryEnumerator enumerator = ld.GetEnumerator(); Assert.NotNull(enumerator); if (data.Length > 0) { Assert.True(enumerator.MoveNext()); DictionaryEntry current = (DictionaryEntry)enumerator.Current; ld.Remove("key"); Assert.Equal(current, enumerator.Current); Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext()); Assert.Throws<InvalidOperationException>(() => enumerator.Reset()); } else { ld.Add("newKey", "newValue"); Assert.Throws<InvalidOperationException>(() => enumerator.MoveNext()); } }
public static void GetEnumeratorTest(ListDictionary ld, KeyValuePair<string, string>[] data) { bool repeat = true; IDictionaryEnumerator enumerator = ld.GetEnumerator(); Assert.NotNull(enumerator); while (repeat) { Assert.Throws<InvalidOperationException>(() => enumerator.Current); foreach (KeyValuePair<string, string> element in data) { Assert.True(enumerator.MoveNext()); DictionaryEntry entry = (DictionaryEntry)enumerator.Current; Assert.Equal(entry, enumerator.Current); Assert.Equal(element.Key, entry.Key); Assert.Equal(element.Value, entry.Value); Assert.Equal(element.Key, enumerator.Key); Assert.Equal(element.Value, enumerator.Value); } Assert.False(enumerator.MoveNext()); Assert.Throws<InvalidOperationException>(() => enumerator.Current); Assert.False(enumerator.MoveNext()); enumerator.Reset(); enumerator.Reset(); repeat = false; } }
static void Main(string[] args) { Console.WriteLine("============StringCollection==========="); String[] myArr = new String[] { "red", "orange", "yellow", "green", "blue", "indigo", "violet" }; StringCollection myCol = new StringCollection(); myCol.Add("Apple"); myCol.Add("Orange"); myCol.Add("Mango"); myCol.AddRange(myArr); foreach (var item2 in myCol) { Console.WriteLine(item2); } Console.WriteLine("count of string collection: " + myCol.Count); Console.WriteLine("CopyTo:====="); string[] str1 = new string[myCol.Count]; myCol.CopyTo(str1, 0); foreach (var item1 in str1) { Console.WriteLine(item1); } Console.WriteLine("contains method"); Console.WriteLine(myCol.Contains("Mango")); Console.WriteLine("Insert: dear"); myCol.Insert(5, "dear"); StringEnumerator myEnumerator = myCol.GetEnumerator(); while (myEnumerator.MoveNext()) { Console.WriteLine("{0}", myEnumerator.Current); } Console.WriteLine(); Console.WriteLine("============StringDictionary==========="); StringDictionary myCol1 = new StringDictionary(); myCol1.Add("red", "rojo"); myCol1.Add("green", "verde"); myCol1.Add("blue", "azul"); Console.WriteLine("contains key red :{0}", myCol1.ContainsKey("red")); Console.WriteLine("containe value 'azul': {0}", myCol1.ContainsValue("azul")); Console.WriteLine("remove key------"); myCol1.Remove("red"); IEnumerator myEnumerator1 = myCol1.GetEnumerator(); foreach (DictionaryEntry de in myCol1) { Console.WriteLine("{0} {1}", de.Key, de.Value); } Console.WriteLine(); Console.WriteLine("============ListDictionary==========="); ListDictionary myCol2 = new ListDictionary(); myCol2.Add("Braeburn Apples", "1.49"); myCol2.Add("Fuji Apples", "1.29"); myCol2.Add("Gala Apples", "1.49"); myCol2.Add("Golden Delicious Apples", "1.29"); myCol2.Add("Granny Smith Apples", "0.89"); myCol2.Add("Red Delicious Apples", "0.99"); Console.WriteLine("CopyTo==============="); DictionaryEntry[] myArr1 = new DictionaryEntry[myCol2.Count]; myCol2.CopyTo(myArr1, 0); foreach (var arr1 in myArr1) { Console.WriteLine("{0}-->{1}", arr1.Key, arr1.Value); } Console.WriteLine("Printing the element list using GetEnumerator method-----"); IEnumerator myEnumerator2 = myCol2.GetEnumerator(); foreach (DictionaryEntry de in myCol2) { Console.WriteLine("{0} {1}", de.Key, de.Value); } Console.WriteLine(); Console.WriteLine("============HybridDictionary==========="); HybridDictionary myCol3 = new HybridDictionary(); myCol3.Add("Braeburn Apples", "1.49"); myCol3.Add("Fuji Apples", "1.29"); myCol3.Add("Gala Apples", "1.49"); myCol3.Add("Golden Delicious Apples", "1.29"); myCol3.Add("Granny Smith Apples", "0.89"); myCol3.Add("Red Delicious Apples", "0.99"); myCol3.Add("Plantain Bananas", "1.49"); myCol3.Add("Yellow Bananas", "0.79"); foreach (DictionaryEntry de in myCol3) { Console.WriteLine(" {0,-25} {1}", de.Key, de.Value); } Console.WriteLine(); Console.WriteLine("Number of elements in myDict are :{0} ", myCol3.Count); Console.WriteLine("After Remove======="); myCol3.Remove("Gala Apples"); foreach (DictionaryEntry de in myCol3) { Console.WriteLine(" {0,-25} {1}", de.Key, de.Value); } }
public IEnumerator GetEnumerator() { return(new DictionaryNodeCollectionEnumerator(dict.GetEnumerator(), isKeyList)); }
IEnumerator IEnumerable.GetEnumerator() { return(connection_string_values.GetEnumerator()); }