从 List 转换为 IEnumerable 格式 [英] Convert from List into IEnumerable format
本文介绍了从 List 转换为 IEnumerable 格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
IEnumerable<Book> _Book_IE
List<Book> _Book_List
如何将_Book_List
转成IEnumerable
格式?
推荐答案
您不需要转换它.List
实现了IEnumerable
接口所以它已经是一个可枚举.
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;
}
以及:
public void ProcessBooks(IEnumerable<Book> books)
{
// do something with those books
}
可以调用:
List<Book> books = FetchEmFromSomewhere();
ProcessBooks(books);
这篇关于从 List 转换为 IEnumerable 格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文