Reputation: 823
public void CheckFileType(string directoryPath)
{
IEnumerator files = Directory.GetFiles(directoryPath).GetEnumerator();
}
The error: Error 1 Using the generic type 'System.Collections.Generic.IEnumerator' requires 1 type arguments
Upvotes: 0
Views: 260
Reputation: 203802
The type you are referring to is generic, which means you need to supply a generic argument, like so:
IEnumerator<string> files = [...];
It so happens that there is a non-generic version of IEnumerator
, but it's in the System.Collections
namespace, not the System.Collections.Generic
namespace. If you want to use the non-generic version (which you really shouldn't; you should use the generic version) you'll need to add a using
for that namespace or use the fully qualified name.
Upvotes: 1
Reputation: 137108
You need to declare what type you're enumerating over:
IEnumerator<string> files = Directory.GetFiles(directoryPath).GetEnumerator();
If you're unsure of the type use var
:
var files = Directory.GetFiles(directoryPath).GetEnumerator();
then the compiler will do all the hard work for you.
Upvotes: 4
Reputation: 2887
IEnumerator<T>
is generic and requires a type, for example:
IEnumerator<string> files = Directory.GetFiles(directoryPath).GetEnumerator();
Upvotes: 2