本文整理匯總了C#中System.Collections.Specialized.HybridDictionary.GetEnumerator方法的典型用法代碼示例。如果您正苦於以下問題:C# HybridDictionary.GetEnumerator方法的具體用法?C# HybridDictionary.GetEnumerator怎麽用?C# HybridDictionary.GetEnumerator使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Collections.Specialized.HybridDictionary
的用法示例。
在下文中一共展示了HybridDictionary.GetEnumerator方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: DefaultValues
public void DefaultValues ()
{
HybridDictionary hd = new HybridDictionary (100);
Assert.AreEqual (0, hd.Count, "Count");
Assert.IsFalse (hd.IsFixedSize, "IsFixedSize");
Assert.IsFalse (hd.IsReadOnly, "IsReadOnly");
Assert.IsFalse (hd.IsSynchronized, "IsSynchronized");
Assert.AreEqual (0, hd.Keys.Count, "Keys");
Assert.AreEqual (0, hd.Values.Count, "Values");
Assert.AreSame (hd, hd.SyncRoot, "SyncRoot");
Assert.IsNotNull (hd.GetEnumerator (), "GetEnumerator");
Assert.IsNotNull ((hd as IEnumerable).GetEnumerator (), "IEnumerable.GetEnumerator");
}
示例2: Test01
public void Test01()
{
HybridDictionary hd;
IDictionaryEnumerator en;
DictionaryEntry curr; // Enumerator.Current value
DictionaryEntry de; // Enumerator.Entry value
Object k; // Enumerator.Key value
Object v; // Enumerator.Value
const int BIG_LENGTH = 100;
// simple string values
string[] valuesShort =
{
"",
" ",
"$%^#",
System.DateTime.Today.ToString(),
Int32.MaxValue.ToString()
};
// keys for simple string values
string[] keysShort =
{
Int32.MaxValue.ToString(),
" ",
System.DateTime.Today.ToString(),
"",
"$%^#"
};
string[] valuesLong = new string[BIG_LENGTH];
string[] keysLong = new string[BIG_LENGTH];
for (int i = 0; i < BIG_LENGTH; i++)
{
valuesLong[i] = "Item" + i;
keysLong[i] = "keY" + i;
}
// [] HybridDictionary GetEnumerator()
//-----------------------------------------------------------------
hd = new HybridDictionary();
// [] Enumerator for empty dictionary
//
en = hd.GetEnumerator();
IEnumerator en2;
en2 = ((IEnumerable)hd).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; });
// ---------------------------------------------------------
// [] Enumerator for Filled dictionary - list
// ---------------------------------------------------------
//
for (int i = 0; i < valuesShort.Length; i++)
{
hd.Add(keysShort[i], valuesShort[i]);
}
en = hd.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 < hd.Count; i++)
{
res = en.MoveNext();
if (!res)
{
Assert.False(true, string.Format("Error, MoveNext returned false", i));
}
curr = (DictionaryEntry)en.Current;
//.........這裏部分代碼省略.........
示例3: GetDictionaryEnumerator
/// <summary>
/// IDictionary interface that returns an enumerator on the dictionary contents
/// </summary>
/// <returns>Returns an enumerator on the dictionary contents</returns>
protected IDictionaryEnumerator GetDictionaryEnumerator()
{
HybridDictionary namespaceTable = new HybridDictionary(_lastDecl);
for (int thisDecl = 0; thisDecl < _lastDecl; thisDecl++)
{
if (_nsDeclarations[thisDecl].Uri != null)
{
namespaceTable[_nsDeclarations[thisDecl].Prefix] = _nsDeclarations[thisDecl].Uri;
}
}
return namespaceTable.GetEnumerator();
}
示例4: Test01
//.........這裏部分代碼省略.........
{
// verify that dictionary is copied correctly
//
if (String.Compare(hd[keysShort[i]].ToString(), ((DictionaryEntry)destination.GetValue(i + len)).Value.ToString()) != 0)
{
Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Value, hd[keysShort[i]]));
}
// verify keysShort
if (String.Compare(keysShort[i], ((DictionaryEntry)destination.GetValue(i + len)).Key.ToString()) != 0)
{
Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i + len)).Key, keysShort[i]));
}
}
// [] many simple strings and CopyTo(Array, 0)
//
hd.Clear();
cnt = hd.Count;
len = valuesLong.Length;
for (int i = 0; i < len; i++)
{
hd.Add(keysLong[i], valuesLong[i]);
}
if (hd.Count != len)
{
Assert.False(true, string.Format("Error, count is {0} instead of {1}", hd.Count, len));
}
destination = Array.CreateInstance(typeof(Object), len);
hd.CopyTo(destination, 0);
//
//
IDictionaryEnumerator en = hd.GetEnumerator();
en.MoveNext();
// items are copied in the same order they are enumerated
for (int i = 0; i < len; i++)
{
// verify that dictionary is copied correctly
//
Object k = en.Key;
if (String.Compare(hd[k].ToString(), ((DictionaryEntry)destination.GetValue(i)).Value.ToString()) != 0)
{
Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Value.ToString(), hd[k]));
}
if (String.Compare(k.ToString(), ((DictionaryEntry)destination.GetValue(i)).Key.ToString()) != 0)
{
Assert.False(true, string.Format("Error, copied \"{1}\" instead of \"{2}\"", i, ((DictionaryEntry)destination.GetValue(i)).Key.ToString(), k.ToString()));
}
en.MoveNext();
}
// [] many simple strings and CopyTo(Array, middle_index)
//
hd.Clear();
hd.Clear();
len = valuesLong.Length;
for (int i = 0; i < len; i++)
{
hd.Add(keysLong[i], valuesLong[i]);
}
if (hd.Count != len)