从列表转换成IEnumerable的格式 [英] Convert from List into IEnumerable format

查看:109
本文介绍了从列表转换成IEnumerable的格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IEnumerable<Book> _Book_IE
List<Book> _Book_List

应如何才能转换 _Book_List 的IEnumerable 格式呢?

推荐答案

您无需将其转换。 列表&LT; T&GT; 实施< A HREF =htt​​p://msdn.microsoft.com/en-us/library/9eekhta0.aspx> 的IEnumerable&LT; T&GT; 接口,所以它是已经是一个枚举。

You don't need to convert it. List<T> implements the IEnumerable<T> interface so it is already an enumerable.

这意味着你可以完全正常的有以下几种:

This means that you can perfectly fine 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);

这篇关于从列表转换成IEnumerable的格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆