https://stackoverflow.com/questions/12390971/why-there-is-two-completely-different-version-of-reverse-for-list-and-ienumerabl

It is worth noting that the list method is a lot older than the extension method. The naming was likely kept the same as Reverse seems more succinct简洁的 than BackwardsIterator.

If you want to bypass the list version and go to the extension method, you need to treat the list like an IEnumerable<T>:

var numbers = new List<int>();
numbers.Reverse(); // hits list
(numbers as IEnumerable<int>).Reverse(); // hits extension

Or call the extension method as a static method:

Enumerable.Reverse(numbers);

Note that the Enumerable version will need to iterate the underlying enumerable entirely in order to start iterating it in reverse. If you plan on doing this multiple times over the same enumerable, consider permanently reversing the order and iterating it normally.

https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1.reverse?view=netframework-4.7.2  List<T>.Reverse

这个方法直接操作了源数据

https://docs.microsoft.com/en-us/dotnet/api/system.linq.enumerable.reverse?view=netframework-4.7.2    Enumerable.Reverse(IEnumerable<TSource>)

这个方法不操作源数据,会返回结果

public static System.Collections.Generic.IEnumerable<TSource> Reverse<TSource> (this System.Collections.Generic.IEnumerable<TSource> source);
    [Test]
public void ReverseTest()
{
List<int> list = new List<int>() {, , };
list.Reverse();
foreach (var item in list)
{
Console.WriteLine(item);
} IEnumerable<int> test = list;
test.Reverse();
foreach (var item in list)
{
Console.WriteLine(item);
} }

Why there is two completely different version of Reverse for List and IEnumerable?的更多相关文章

  1. Palindromes _easy version(reverse)

    Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”.   Input 输入包 ...

  2. Bypass WAF Cookbook

    PS.之前一直想把零零碎碎的知识整理下来,作为知识沉淀下来,正好借着wooyun峰会的机会将之前的流程又梳理了一遍,于是就有了下文.也希望整理的内容能给甲方工作者或则白帽子带来一些收获. 0x00 概 ...

  3. 我的WafBypass之道

    0x00 前言  去年到现在就一直有人希望我出一篇关于waf绕过的文章,我觉得这种老生常谈的话题也没什么可写的.很多人一遇到waf就发懵,不知如何是好,能搜到的各种姿势也是然并卵.但是积累姿势的过程也 ...

  4. .net的retrofit--WebApiClient底层篇

    前言 本篇文章的内容是WebApiClient底层说明,也是WebApiClient系列接近尾声的一篇文章,如果你没有阅读过之前的的相关文章,可能会觉得本文章的内容断层,WebApiClient系列文 ...

  5. Django REST framework反向生成url

    Django REST framework是一个基于Django的框架,REST framework又是怎么反向生成url的呢?? 在前面的例子中,知道在REST framework中有6种版本控制的 ...

  6. ASP.NET Core Web API下事件驱动型架构的实现(四):CQRS架构中聚合与聚合根的实现

    在前面两篇文章中,我详细介绍了基本事件系统的实现,包括事件派发和订阅.通过事件处理器执行上下文来解决对象生命周期问题,以及一个基于RabbitMQ的事件总线的实现.接下来对于事件驱动型架构的讨论,就需 ...

  7. Django rest framework源码分析(4)----版本

    版本 新建一个工程Myproject和一个app名为api (1)api/models.py from django.db import models class UserInfo(models.Mo ...

  8. 06 Django REST Framework 版本控制

    01-版本控制 对接口进行版本控制只是一种杀死已部署客户端的“礼貌”方式. - 罗伊菲尔丁. 1. API版本控制允许您更改不同客户端之间的行为.REST框架提供了许多不同的版本控制方案. 2. 版本 ...

  9. 我的WafBypass之道(SQL注入篇)

    原帖地址:https://xianzhi.aliyun.com/forum/read/349.html 0x00 前言 去年到现在就一直有人希望我出一篇关于waf绕过的文章,我觉得这种老生常 谈的话题 ...

随机推荐

  1. meta 跳转

    强无敌. 是否厌倦了页面枯燥的跳转? 试试这样的跳转吧. Duration:表示滤镜特效的持续时间(单位:秒) Transition:滤镜类型.表示使用哪种特效,取值为0-23. <Meta h ...

  2. Permutation Bo (数学证明)

    当在两端时:共有n * (n - 1)种组合,满足条件的有,计算可得, counter = n * (n - 1) / 2. 其他位置时:共有n * (n - 1) * (n - 2) 种组合,满足条 ...

  3. 什么是ASCII

    以下内容是从百度百科学的 1)ASCII(American Standard Code for Information Interchange:美国信息交换标准代码) 2)产生原因 在计算机中,所有的 ...

  4. 什么是FEBS

    FEBS后台权限管理系统      FEBS是一个简单高效的后台权限管理系统.项目基础框架采用全新的Java Web开发框架 —— Spring Boot2.0.4,消除了繁杂的XML配置,使得二次开 ...

  5. js如何获取服务器端时间?

    用js做时间校正,获取本机时间,是存在bug的. 使用js也可获取到服务器时间,原理是使用 ajax请求,返回的头部信息就含有服务器端的时间信息,获取到就可以了.以下: 1.依赖jQuery 代码: ...

  6. byte & 0xff char 转换

    https://blog.csdn.net/lixingtao0520/article/details/75450883 版权声明:本文为博主原创文章,转载请注明作者与出处,http://blog.c ...

  7. flask框架----上下文管理

    一.上下文管理相关知识点: a.类似于本地线程 创建Local类: { 线程或协程唯一标识: { 'stack':[request],'xxx':[session,] }, 线程或协程唯一标识: { ...

  8. 合并两个JsonArray

    //合并两个JSONArray public static String joinJSONArray(JSONArray mData, JSONArray array) { StringBuffer ...

  9. JavaScript快速总结之一

    js格式和位置: <!--js内容可以在head中,也可以在body中,不同位置执行顺序会有区别 ,另外也可以单独放到一个js文件中,这样方便维护和修改,而且,可以加快html页面的加载速度.- ...

  10. session(概念、session对象的获取、删除、验证)

    # 1.session(会话)是什么? 服务器为了保存用户状态而创建的一个特殊的对象. 注: 当浏览器访问服务器时,服务器会创建一个session对象(该对象有一个唯一的id,一般称之为session ...