本文整理汇总了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)