我的任务是在2008年为VB.NET创建Directory.EnumerateFiles版本。
我已经设法在c#中为VS2008做了这个:
public IEnumerable<string> GetFileList(string fileSearchPattern, string rootFolderPath)
{
Queue<string> pending = new Queue<string>();
pending.Enqueue(rootFolderPath);
string[] tmp;
while (pending.Count > 0)
{
rootFolderPath = pending.Dequeue();
tmp = Directory.GetFiles(rootFolderPath, fileSearchPattern, SearchOption.AllDirectories);
for (int i = 0; i < tmp.Length; i++)
{
yield return tmp[i];
}
tmp = Directory.GetDirectories(rootFolderPath);
for (int i = 0; i < tmp.Length; i++)
{
pending.Enqueue(tmp[i]);
}
}
}
现在我正在将其翻译为vb.net:
Private Function GetfileList(ByVal fileSearchPattern As String, ByVal rootFolderPath As String) As IEnumerable(Of String)
Dim pending As New Queue(Of String)()
pending.Enqueue(rootFolderPath)
Dim tmp() As String
While (pending.Count > 0)
rootFolderPath = pending.Dequeue()
tmp = Directory.GetFiles(rootFolderPath, fileSearchPattern, SearchOption.AllDirectories)
For counter As Integer = 0 To tmp.Length - 1
'Yield gives an error as it does not appear to be a keyword!!
tmp = Directory.GetDirectories(rootFolderPath)
For i As Integer = 0 To tmp.Length - 1
pending.Enqueue(tmp(i))
Next
Next
End While
End Function
但是Yield关键字给我一个错误,因为未声明&#39;?
是否有替代vb.net 2008支持的收益?