Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I use the following IEnumerable<string>?

I'm getting the following error:

Error   25  The type or namespace name 'IEnumerable' could not be found (are you missing a using directive or an assembly reference?)   C:\Development\Leverage\Leverage\Reports\SurveyLevel.aspx.cs    39  17  Leverage

because of this line:

  private IEnumerable<string> GetDateParameters()

How do I deal with this? I tried to add in the line:

using System.IDisposable

at the top, but this doesn't fix it.

like image 981
Caffeinated Avatar asked Feb 27 '13 20:02

Caffeinated


4 Answers

As others have said, you're missing using System.Collections.Generic;.

But that's giving you a fish; we should be teaching you to catch your own fish.

The way to solve this problem on your own is:

Enter the name of the type into your favourite search engine, and see what comes back:

IEnumerable(T) Interface (System.Collections.Generic)

http://msdn.microsoft.com/en-us/library/9eekhta0

Exposes the enumerator, which supports a simple iteration over a collection of a specified type.

See the bit that I highlighted in bold there? That's the namespace that you're missing.

If you still get the error then you are likely missing a reference; you can find out which DLL you have failed to reference by clicking on the link and reading the documentation page; it will tell you which DLL to reference.

like image 142
Eric Lippert Avatar answered Nov 05 '22 17:11

Eric Lippert


You are missing a using System.Collections.Generic; statement at the top of the code file.

The generic IEnumerable<T> type cannot be found directly.

You could declare the full name instead:

private System.Collections.Generic.IEnumerable<string> GetDateParameters()
like image 29
Oded Avatar answered Nov 05 '22 17:11

Oded


IEnumerable is in System.Collections

IEnumerable<T> is in System.Collections.Generic

like image 2
Khan Avatar answered Nov 05 '22 15:11

Khan


You just need to add System.Collections.Generic namespace top of your code.

IEnumerable<T> belongs on this namespace in mscorlib.dll assembly.

You can use it like;

private System.Collections.Generic.IEnumerable<string> GetDateParameters()
like image 1
Soner Gönül Avatar answered Nov 05 '22 17:11

Soner Gönül