我想实现一个IEnumerator.但它会导致错误
public class WachableDictionaryEnumerator : IEnumerator<TVal>
{
private TVal[] a;
private int len;
public bool MoveNext()
{
len = len + 1;
return len < a.Length;
}
public object Current
{
get
{
return a[len];
}
}
public TVal Current
{
get
{
return a[len];
}
}
public void Dispose()
{
a = null;
len = 0;
}
public void Reset()
{
len = 0;
}
}
Run Code Online (Sandbox Code Playgroud)
错误是:
错误5类型'CPS.Manipulation.WatchableDictionary.WachableDictionaryEnumerator'已包含'当前'的定义D:\ CE\Supins\Cyan Pembuat Soal\Required Manipulation\Class1.cs 32 25所需的操作
但是如果我删除了一个Current对象,那么错误就是
错误21'CPS.Manipulation.WatchableDictionary.WachableDictionaryEnumerator'未实现接口成员'System.Collections.Generic.IEnumerator.Current'.'CPS.Manipulation.WatchableDictionary.WachableDictionaryEnumerator.Current'无法实现'System.Collections.Generic.IEnumerator.Current',因为它没有匹配的返回类型'TVal'.D:\ CE\Supins\Cyan Pembuat Soal\Required …
我想尝试制作自己的文件浏览器.我有一个算法来枚举所有驱动器中的所有目录.但它运行得太慢了.这是我的代码:
public ExplorerForm()
{
InitializeComponent();
this.SuspendLayout();//Without this, it will be far more slow again!
string[] a = System.IO.Directory.GetLogicalDrives();// a is used for drive array
for(int b = 0; b < a.Length; b++)//B is an enumerator. Ussually it is only one letter
{
//Defining the node
TreeNode c = new TreeNode();//c i place for TreeNode
c.Text = a[b].Substring(0,2);
c.Tag = a[b];
ApplyNodes(a[b], ref c);
if(c != null) tv.Nodes.Add(a)
}
this.ResumeLayout(false);
}
private void ApplyNodes(string a, ref TreeNode b)//a=directory, b applied TreeNode …Run Code Online (Sandbox Code Playgroud)