简体   繁体   中英

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.

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.

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()

IEnumerable is in System.Collections

IEnumerable<T> is in System.Collections.Generic

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()

Above answers are good. In my case, even after following the above answers it did not resolve the issue. Still the red squiggly constantly appeared.

Issue was the Framework of the project. It was by default set to .NET Framework 4.0.3 and changing to .NET Framework 4.0.0 will also help.

在此输入图像描述

Save your Project properties after the change, build and it should all work.

Hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM