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

17,123

Solution 1

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.

Solution 2

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

Solution 3

IEnumerable is in System.Collections

IEnumerable<T> is in System.Collections.Generic

Solution 4

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()
Share:
17,123
Caffeinated
Author by

Caffeinated

I like time-saving. And coffee. http://thenicestplaceontheinter.net/

Updated on October 09, 2022

Comments

  • Caffeinated
    Caffeinated over 1 year

    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.

  • Servy
    Servy about 11 years
    But he's using IEnumerable<string>, which is not, it's in System.Collections.Generic.
  • Servy
    Servy about 11 years
    Or if using visual studio just right click the type name -> Resolve -> choose to add a using or prefix the namespace.
  • Caffeinated
    Caffeinated about 11 years
    I'm happy now. I see now how to find the info. Thank you so much!
  • David Tansey
    David Tansey over 7 years
    "Give a man a fish and you feed him for a day. But teach him how to use the Internet and he won't bother you for weeks."