我正在试图解决在http://users.metropolia.fi/~dangm/blog/?p=67上显示的问题。 我是新来的c#语言。我想通过使用枚举数的字典和特定条件迭代。所以有两个变量current和previous.current指向dictionary.previous的第一个元素。previous指向previous中的元素。在迭代在字典我循环像FOLL迭代和修改字典
previous=current;
current.MoveNext();
问题是,当我们反复第一次直通整部字典之前的点最后一个元素的字典和当前点随机密钥值对RawVariable(0,0),但现在时我们通过词典第二次迭代,我希望当前指向字典中的第一个元素。我是否使当前点指向某个具有特定键或值的元素
这是我的代码片段
public void falling_disks(int[] A, int[] B)
{
Dictionary<int, int> filledDictionary = filldictionary(d1, A);
//previous stores the previous element in dictionary
var previous = filledDictionary .GetEnumerator();
//current stores next element of previous
var current = filledDictionary .GetEnumerator();
current.MoveNext();
//for each incoming element in array B
foreach (int ele in B)
{
//check if the current key is filled in hashtable h1 that is check if it
//is already added
if (!checkifthatvalueisfilled(current.Current.Key))
{
//if not check if current value is less than or equal to element
while ((current.Current.Value >= ele))
{
//assign previous to current
previous = current;
//move current to next position
current.MoveNext();
}
listofitemstoremove.Add(previous.Current.Key);
}
else
{
listofitemstoremove.Add(current.Current.Key);
}
foreach (int item in listofitemstoremove)
{
if (!(h1.ContainsKey(item)))
h1.Add(item, true);
}
}
Console.WriteLine(listofitemstoremove.Capacity);
}
public bool checkifthatvalueisfilled(int key)
{
if (h1.ContainsValue(h1.ContainsKey(key)) == true)
return true;
else return false;
}
}
您的问题目前*非常*不清楚。你的代码使用了几个根本没有解释的变量和方法,你的文本解释很难理解。请澄清。 – 2013-03-07 04:41:34
一个猜测......将'current'指定给开始if(ele.Equals(b.Last())'? – 2013-03-07 04:47:02
是否要在Dictionary中搜索某些值 – 2013-03-07 05:18:41