[英]How can I count the number of elements in IEnumerator?
I am getting all files in a directory by following code. 我正在通过以下代码将目录中的所有文件。
IEnumerator FILES = Directory.GetFiles(
DIRECTORY_PATH).GetEnumerator();
How can I get the total number of files? 如何获得文件总数? There's no FILES.Count();
没有FILES.Count();
Directory.GetFiles(@"C:\yourdir").Length
直接给你数
First you can get your files string[]
, count the numbers in it, then get your enumerator: 首先,您可以获取文件string[]
,计算其中的数字,然后获取枚举数:
string[] files = Directory.GetFiles(DIRECTORY_PATH);
int count = files.Length;
IEnumerator enumerator = files.GetEnumerator();
If you really want to stick with " GetEnumerator()
" ... 如果您真的想坚持使用“ GetEnumerator()
” ...
IEnumerator files = Directory.GetFiles(DIRECTORY_PATH).GetEnumerator();
int count = 0;
while (files.MoveNext())
{
count++;
}
// after this loop you will have total files count in count varibale.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.