You don’t need to convert it. List<T>
implements the IEnumerable<T>
interface so it is already an enumerable.
This means that it is perfectly fine to have the following:
public IEnumerable<Book> GetBooks() { List<Book> books = FetchEmFromSomewhere(); return books; }
as well as:
public void ProcessBooks(IEnumerable<Book> books) { // do something with those books }
which could be invoked:
List<Book> books = FetchEmFromSomewhere(); ProcessBooks(books);
Related Posts:
- Can anyone explain IEnumerable and IEnumerator to me? [closed]
- How to fix No connection could be made because the target machine actively refused it 127.0.0.1:64527
- failed to load resource: the server response with a status 500 (internal server error)
- ASP.NET 5 MVC: unable to connect to web server ‘IIS Express’
- Why is this code throwing an InvalidOperationException?
- Twilio TwilioRestClient does not contain a definition for SendSmsMessage
- System.web.mvc missing
- Compiler Error Message: The compiler failed with error code -2146232576
- How can I secure passwords stored inside web.config?
- Process exists with ExitCode 255
- IEnumerable vs List – What to Use? How do they work?
- ASP.NET MVC Page Won’t Load and says “The resource cannot be found”
- How do I target @Model within a src of an image tag?
- Converting from IEnumerable to List
- HTML.ActionLink method
- Could not load file or assembly ‘Microsoft.Web.Infrastructure,
- Styles.Render in MVC4
- What does ModelState.IsValid do?
- There is no ViewData item of type ‘IEnumerable
‘ that has the key country - Error Message: Type or namespace definition, or end-of-file expected
- The model item passed into the dictionary is of type .. but this dictionary requires a model item of type
- CS1617: Invalid option ‘6’ for /langversion; must be ISO-1, ISO-2, 3, 4, 5 or Default
- The name ‘ViewBag’ does not exist in the current context – Visual Studio 2015
- Authorization has been denied for this request – New Web API Project
- System.ArgumentNullException: Value cannot be null. Parameter name: source
- How to make Check Box List in ASP.Net MVC
- Effectively use async/await with ASP.NET Web API
- What should I use an IEnumerable or IList? [duplicate]
- .Net 4.8 Support for Windows 10 ends in 26 days?
- What is a NullReferenceException, and how do I fix it?
- How do I get a random YouTube video with the YouTube API?
- What is a NullReferenceException, and how do I fix it?
- Unexplained crashes related to ntdll.dll
- CS0120: An object reference is required for the nonstatic field, method, or property ‘foo’
- What is the difference between declarative and imperative paradigm in programming?
- Group by in LINQ
- C# An established connection was aborted by the software in your host machine
- OnCollisionEnter() not working in Unity3D
- Difference between virtual and abstract methods
- How to open .dll files to see what is written inside?
- how does Request.QueryString work?
- C# Java HashMap equivalent
- System.Net.Http: missing from namespace? (using .net 4.5)
- Windows .NET API / Windows 7 / Bluetooth communication with Intel Curie Arduino / Genuino 101
- WFP Grid: MouseRightButtonDown firing occuring BEFORE SelectionChanged on grid. Causing syncing issue
- Can’t add script component because the script class cannot be found?
- ‘do…while’ vs. ‘while’
- Visual Studio /**/ comment shortcut?
- Unable to resolve service for type while attempting to activate
- Multiple Inheritance in C#
- Wait one second in running program
- Deserialize JSON with C#
- “Error while trying to run project: Unable to start program”. Can run program only once. Then VS needs restart
- What is WebResource.axd?
- Associating enums with strings in C#
- Proper Linq where clauses
- Validation failed for one or more entities. See ‘EntityValidationErrors’ property for more details
- How to resolve this System.IO.FileNotFoundException
- What is the best way to implement a “timer”?
- How to Use TextureBrush for painting an Image
- C# compiler error: “not all code paths return a value”
- SmtpException: Unable to read data from the transport connection: net_io_connectionclosed
- How can I get the application’s path in a .NET console application?
- How do I encode and decode a base64 string?
- How to keep console window open
- Tree data structure in C#
- What is 0x10 in decimal?
- Visual Studio: The Operation could not be completed. The parameter is incorrect
- Member ‘
‘ cannot be accessed with an instance reference - Sequence contains no matching element
- when do you need .ascx files and how would you use them?
- How to open a new form from another form
- C# – How to convert string to char?
- The entity type
is not part of the model for the current context - Recommendation for C# Matrix Library
- Deep cloning objects
- Regular expression “^[a-zA-Z]” or “[^a-zA-Z]”
- .NET graph library around?
- Input string was not in a correct format
- Verify a method call using Moq
- XmlSerializer – There was an error reflecting type
- Run Command Prompt Commands
- Cannot implicitly convert type ‘System.Collections.Generic.List< >‘ to ‘System.Collections.Generic.IList< >‘
- How can I wait for a thread to finish with .NET?
- How do I exit a WPF application programmatically?
- How to deserialize xml to object [duplicate]
- How can we prepend strings with StringBuilder?
- C# conditional operator error Only assignment, call, increment, decrement, await, and new object expressions can be used as a statement
- Cannot drop database because it is currently in use
- Troubleshooting “program does not contain a static ‘Main’ method” when it clearly does…?
- Unity 5.2.2 changing Visual Studio back to MonoDevelop
- Using FolderBrowserDialog in WPF application
- Is there an equivalent to the C# “var” keyword in C++/CLI?
- The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required?
- Quickest way to compare two generic lists for differences
- What is the easiest way to encrypt a password when I save it to the registry?
- LINQ query on a DataTable
- Key Value Pair List
- Using .Select and .Where in a single LINQ statement
- Memory Leak caused by System.Drawing.Internal.GPStream