本文整理汇总了C#中Dictionary.GetEnumerator方法的典型用法代码示例。如果您正苦于以下问题:C# Dictionary.GetEnumerator方法的具体用法?C# Dictionary.GetEnumerator怎么用?C# Dictionary.GetEnumerator使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Dictionary
的用法示例。
在下文中一共展示了Dictionary.GetEnumerator方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: dictionaryIteration
public static void dictionaryIteration()
{
Console.WriteLine("# Dictionary Iteration Sample");
Dictionary<Int32, String> map = new Dictionary<Int32, String>();
map[10] = "Hello";
map[20] = "Lorem";
map[30] = "Ipsum";
Dictionary<Int32, String>.Enumerator iterator = map.GetEnumerator();
while (iterator.MoveNext())
{
KeyValuePair<Int32, String> pair = iterator.Current;
Console.WriteLine(pair.Key + " : " + pair.Value);
}
IEnumerator<KeyValuePair<Int32, String>> iterator2 = map.GetEnumerator();
while (iterator2.MoveNext())
{
KeyValuePair<Int32, String> pair = iterator2.Current;
Console.WriteLine(pair.Key + " : " + pair.Value);
}
foreach (KeyValuePair<Int32, String> pair in map)
{
Console.WriteLine(pair.Key + " : " + pair.Value);
}
}
示例2: Run
public Task Run()
{
var allTestMethods = testMethodExtractor.GetTestMethods();
var testMethodsDistribution = new Dictionary<ITestRunner, IList<IMethodInfo>>();
foreach (var runner in testRunners)
{
testMethodsDistribution.Add(runner, new List<IMethodInfo>());
}
var testMethodsDistributionEnum = testMethodsDistribution.GetEnumerator();
foreach (var testMethod in allTestMethods)
{
KeyValuePair<ITestRunner, IList<IMethodInfo>> distribution;
if (testMethodsDistributionEnum.MoveNext())
{
distribution = testMethodsDistributionEnum.Current;
}
else
{
testMethodsDistributionEnum = testMethodsDistribution.GetEnumerator();
testMethodsDistributionEnum.MoveNext();
distribution = testMethodsDistributionEnum.Current;
}
distribution.Value.Add(testMethod);
}
var allRunnersTasks = testMethodsDistribution.Select(r=>r.Key.Run(r.Value.ToArray()));
return Task.Factory.StartNew( () => Task.WaitAll(allRunnersTasks.ToArray()));
}
示例3: foo
public void foo()
{
long n = long.Parse(Console.ReadLine());
string[] sp = Console.ReadLine().Split(' ');
Dictionary<long, long> dict = new Dictionary<long, long>();
for (long i = 0; i < n; i++)
{
long a = long.Parse(sp[i]);
if (dict.ContainsKey(a))
{
dict[a]++;
}
else
{
dict.Add(a, 1);
}
}
Dictionary<long, long> dict1 = new Dictionary<long, long>();
var e = dict.GetEnumerator();
while (e.MoveNext())
{
var p = e.Current;
dict1.Add(p.Key, p.Value);
}
sp = Console.ReadLine().Split(' ');
for (long i = 0; i < n - 1; i++)
{
long a = long.Parse(sp[i]);
dict[a]--;
if (dict[a] == 0)
dict.Remove(a);
}
e = dict.GetEnumerator();e.MoveNext();
Console.WriteLine(e.Current.Key);
dict1[e.Current.Key]--;
if (dict1[e.Current.Key] == 0)
dict1.Remove(e.Current.Key);
sp = Console.ReadLine().Split(' ');
for (long i = 0; i < n - 2; i++)
{
long a = long.Parse(sp[i]);
dict1[a]--;
if (dict1[a] == 0)
dict1.Remove(a);
}
e = dict1.GetEnumerator();e.MoveNext();
Console.WriteLine(e.Current.Key);
}
示例4: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("Return the property get_Entry in the IDictionaryEnumerator 1");
try
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("str1", "helloworld");
Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
IDictionaryEnumerator idicEnumer = (IDictionaryEnumerator)enumer;
if (idicEnumer.MoveNext())
{
DictionaryEntry entryVal = idicEnumer.Entry;
if (entryVal.Key.ToString() != "str1" || entryVal.Value.ToString() != "helloworld")
{
TestLibrary.TestFramework.LogError("001", "the ExpectResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例5: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("Return the property get_Current in the IEnumerator 2");
try
{
Dictionary<TestClass, TestClass> dictionary = new Dictionary<TestClass, TestClass>();
TestClass Tkey1 = new TestClass();
TestClass TVal1 = new TestClass();
dictionary.Add(Tkey1, TVal1);
Dictionary<TestClass, TestClass>.Enumerator enumer = dictionary.GetEnumerator();
IEnumerator iEnumer = (IEnumerator)enumer;
while(iEnumer.MoveNext())
{
object objCurrent = iEnumer.Current;
KeyValuePair<TestClass, TestClass> keyVal = new KeyValuePair<TestClass, TestClass>(Tkey1, TVal1);
if (!objCurrent.Equals(keyVal))
{
TestLibrary.TestFramework.LogError("003", "the ExpectResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例6: PostRequest
/// <summary>
///
/// </summary>
/// <param name="url"></param>
/// <param name="referer"></param>
/// <returns></returns>
protected HttpWebRequest PostRequest(string url, string referer, Dictionary<string,string> prams)
{
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Proxy = Proxy;
req.AllowAutoRedirect = false;
req.UserAgent = ConstData.UserAgent;
req.Referer = referer;
req.Headers.Add("Cookie", Cookie);
req.Timeout = 30 * 1000;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
System.Text.StringBuilder sb = new StringBuilder();
Dictionary<string, string>.Enumerator e = prams.GetEnumerator();
while (e.MoveNext())
{
sb.AppendFormat("{0}={1}&", e.Current.Key, e.Current.Value);
}
req.ContentLength = System.Text.Encoding.UTF8.GetByteCount(sb.ToString());
using(System.IO.StreamWriter sw = new System.IO.StreamWriter(req.GetRequestStream()))
{
sw.Write(sb.ToString());
}
return req;
}
示例7: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest1:Invoke the method GetEnumerator in ValueCollection Generic IEnumerable 1");
try
{
Dictionary<string, string> dic = new Dictionary<string, string>();
dic.Add("str1", "Test1");
dic.Add("str2", "Test2");
IEnumerable<string> ienumer = (IEnumerable<string>)new Dictionary<string, string>.ValueCollection(dic);
IEnumerator<string> ienumerator = ienumer.GetEnumerator();
Dictionary<string, string>.Enumerator dicEnumer = dic.GetEnumerator();
while (ienumerator.MoveNext() && dicEnumer.MoveNext())
{
if (!ienumerator.Current.Equals(dicEnumer.Current.Value))
{
TestLibrary.TestFramework.LogError("001", "the ExpecResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例8: JSONStructIterator
public JSONStructIterator(JSONEntry oEntry)
{
m_object = oEntry.getObject();
m_enumStruct = m_object.GetEnumerator();
if (m_enumStruct.MoveNext())
m_strCurKey = m_enumStruct.Current.Key;
}
示例9: SetFunctions
private void SetFunctions(Dictionary<string, int> functions)
{
this.m_FunctionsListInputData.m_ListElements.Clear();
if (functions == null)
this.m_FunctionsListInputData.NewOrMatchingElement("Querying instrumentable functions...").enabled = false;
else if (functions.Count == 0)
{
this.m_FunctionsListInputData.NewOrMatchingElement("No instrumentable child functions found").enabled = false;
}
else
{
this.m_FunctionsListInputData.m_MaxCount = Mathf.Clamp(functions.Count + 1, 0, 30);
if (this.m_ShowAllCheckbox)
{
this.m_AllCheckbox = new PopupList.ListElement(" All", false, float.MaxValue);
this.m_FunctionsListInputData.m_ListElements.Add(this.m_AllCheckbox);
}
using (Dictionary<string, int>.Enumerator enumerator = functions.GetEnumerator())
{
while (enumerator.MoveNext())
{
KeyValuePair<string, int> current = enumerator.Current;
PopupList.ListElement listElement = new PopupList.ListElement(current.Key, current.Value != 0);
listElement.ResetScore();
this.m_FunctionsListInputData.m_ListElements.Add(listElement);
}
}
if (!this.m_ShowAllCheckbox)
return;
this.UpdateAllCheckbox();
}
}
示例10: PosTest1
public bool PosTest1()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("Return the property get_Current in the IEnumerator 1");
try
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("str1", "helloworld");
Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
IEnumerator iEnumer = (IEnumerator)enumer;
while (iEnumer.MoveNext())
{
object objCurrent = iEnumer.Current;
KeyValuePair<string, string> keyVal = new KeyValuePair<string, string>("str1", "helloworld");
if (!objCurrent.Equals(keyVal))
{
TestLibrary.TestFramework.LogError("001", "the ExpectResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例11: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("Invoke the method Reset in the IEnumerator 2");
try
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("str1", "helloworld");
Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
IEnumerator iEnumer = (IEnumerator)enumer;
while (iEnumer.MoveNext()) { }
iEnumer.Reset();
while (iEnumer.MoveNext())
{
KeyValuePair<string, string> keyVal1 = (KeyValuePair<string, string>)iEnumer.Current;
if (keyVal1.Key != "str1" || keyVal1.Value != "helloworld")
{
TestLibrary.TestFramework.LogError("001", "the ExpectResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("002", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例12: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("Return the property Current of in the Dictionary Enumerator 2");
try
{
Dictionary<string, string> dictionary = new Dictionary<string, string>();
dictionary.Add("str1", "helloworld");
Dictionary<string, string>.Enumerator enumer = dictionary.GetEnumerator();
if (enumer.MoveNext())
{
KeyValuePair<string, string> keyVal = enumer.Current;
if (keyVal.Key != "str1" || keyVal.Value != "helloworld")
{
TestLibrary.TestFramework.LogError("003", "the ExpectResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例13: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("PosTest2:Invoke the method GetEnumerator in ValueCollection Generic IEnumerable 2");
try
{
Dictionary<TestClass, TestClass> dic = new Dictionary<TestClass, TestClass>();
TestClass TKey1 = new TestClass();
TestClass TVal1 = new TestClass();
TestClass TKey2 = new TestClass();
TestClass TVal2 = new TestClass();
dic.Add(TKey1, TVal1);
dic.Add(TKey2, TVal2);
IEnumerable<TestClass> ienumer = (IEnumerable<TestClass>)new Dictionary<TestClass, TestClass>.ValueCollection(dic);
IEnumerator<TestClass> ienumerator = ienumer.GetEnumerator();
Dictionary<TestClass, TestClass>.Enumerator dicEnumer = dic.GetEnumerator();
while (ienumerator.MoveNext() && dicEnumer.MoveNext())
{
if (!ienumerator.Current.Equals(dicEnumer.Current.Value))
{
TestLibrary.TestFramework.LogError("003", "the ExpecResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例14: PosTest2
public bool PosTest2()
{
bool retVal = true;
TestLibrary.TestFramework.BeginScenario("Return the property get_Entry in the IDictionaryEnumerator 2");
try
{
Dictionary<TestClass,TestClass> dictionary = new Dictionary<TestClass,TestClass>();
TestClass Tkey1 = new TestClass();
TestClass TVal1 = new TestClass();
dictionary.Add(Tkey1,TVal1);
Dictionary<TestClass,TestClass>.Enumerator enumer = dictionary.GetEnumerator();
IDictionaryEnumerator idicEnumer = (IDictionaryEnumerator)enumer;
if (idicEnumer.MoveNext())
{
DictionaryEntry entryVal = idicEnumer.Entry;
if (entryVal.Key != Tkey1 || entryVal.Value != TVal1)
{
TestLibrary.TestFramework.LogError("003", "the ExpectResult is not the ActualResult");
retVal = false;
}
}
}
catch (Exception e)
{
TestLibrary.TestFramework.LogError("004", "Unexpect exception:" + e);
retVal = false;
}
return retVal;
}
示例15: countBananaSplits
public int countBananaSplits(string[] ingredients)
{
Dictionary<string, int> dict = new Dictionary<string, int>();
for (int i = 0; i < ingredients.Length; i++)
{
if (dict.ContainsKey(ingredients[i]))
{
dict[ingredients[i]]++;
}
else
{
dict.Add(ingredients[i], 1);
}
}
if (!dict.ContainsKey("ice cream"))
{
return 0;
}
if (!dict.ContainsKey("banana"))
{
return 0;
}
int ret = 1;
Dictionary<string, int>.Enumerator e = dict.GetEnumerator();
while (e.MoveNext())
{
if (e.Current.Key != "ice cream" && e.Current.Key != "banana")
ret *= (e.Current.Value + 1);
}
return dict["ice cream"]*dict["banana"]*(ret - 1);
}