Why there is two completely different version of Reverse for List and IEnumerable?
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?的更多相关文章
- Palindromes _easy version(reverse)
Problem Description “回文串”是一个正读和反读都一样的字符串,比如“level”或者“noon”等等就是回文串.请写一个程序判断读入的字符串是否是“回文”. Input 输入包 ...
- Bypass WAF Cookbook
PS.之前一直想把零零碎碎的知识整理下来,作为知识沉淀下来,正好借着wooyun峰会的机会将之前的流程又梳理了一遍,于是就有了下文.也希望整理的内容能给甲方工作者或则白帽子带来一些收获. 0x00 概 ...
- 我的WafBypass之道
0x00 前言 去年到现在就一直有人希望我出一篇关于waf绕过的文章,我觉得这种老生常谈的话题也没什么可写的.很多人一遇到waf就发懵,不知如何是好,能搜到的各种姿势也是然并卵.但是积累姿势的过程也 ...
- .net的retrofit--WebApiClient底层篇
前言 本篇文章的内容是WebApiClient底层说明,也是WebApiClient系列接近尾声的一篇文章,如果你没有阅读过之前的的相关文章,可能会觉得本文章的内容断层,WebApiClient系列文 ...
- Django REST framework反向生成url
Django REST framework是一个基于Django的框架,REST framework又是怎么反向生成url的呢?? 在前面的例子中,知道在REST framework中有6种版本控制的 ...
- ASP.NET Core Web API下事件驱动型架构的实现(四):CQRS架构中聚合与聚合根的实现
在前面两篇文章中,我详细介绍了基本事件系统的实现,包括事件派发和订阅.通过事件处理器执行上下文来解决对象生命周期问题,以及一个基于RabbitMQ的事件总线的实现.接下来对于事件驱动型架构的讨论,就需 ...
- Django rest framework源码分析(4)----版本
版本 新建一个工程Myproject和一个app名为api (1)api/models.py from django.db import models class UserInfo(models.Mo ...
- 06 Django REST Framework 版本控制
01-版本控制 对接口进行版本控制只是一种杀死已部署客户端的“礼貌”方式. - 罗伊菲尔丁. 1. API版本控制允许您更改不同客户端之间的行为.REST框架提供了许多不同的版本控制方案. 2. 版本 ...
- 我的WafBypass之道(SQL注入篇)
原帖地址:https://xianzhi.aliyun.com/forum/read/349.html 0x00 前言 去年到现在就一直有人希望我出一篇关于waf绕过的文章,我觉得这种老生常 谈的话题 ...
随机推荐
- SVN windows内修改日志内容(错误解决)
在我的电脑是windows 7,使用TortoiseSVN客户端,选中代码目录,点击右键,选择<显示日志> 显示日志信息 修改原来的日志信息(在需要修改的版本的日志中点击鼠标右键,显示如下 ...
- DX9 DirectX鼠标控制程序 代码
代码实例1: // @time: 2012.3.26 // @author: jadeshu // des: DirectX鼠标控制程序 #include <Windows.h> #inc ...
- html5-文件的基本格式
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8&qu ...
- Ngine X 完全开发指南 读书笔记-前言
一开始接触的编程语言是VF,那是一种可视化编程语言,所谓的可视化,就是运行结果能直接看得到的,非常直观,便于调试,适合刚刚接触编程的新人学习.当时学得懵懂,半知半解,就是感觉程序非常神奇,常常几句代码 ...
- 【Error】:svnrdump: E130003: The XML response contains invalid XML
我这边的使用场景是在对远程服务器进行svnrdump dump操作时出现该问题,因为是对远程仓库多级子目录进行备份,结果出现错误. 在网上搜索了很多,有很多帖子是在checkout的时候出现问题,和我 ...
- Android获取全局Context的方法
Android获取全局Context的方法 Android--应用全局获取Context - 超宇的博客 - CSDN博客https://blog.csdn.net/chaoyu168/article ...
- 证券化代币的时代已经到来,STO将引爆区块链经济
STOs 似乎会在 2019 年取代 ICOs,即使不是完全取代,但置换的比例也会相当大.所有在美上市的公司都将按照 SEC 制定的相关规定进行交易.Vellum Capital 的 CEO 兼管理合 ...
- js获取浏览器信息
function message() { txt = "<p>浏览器代码名: " + navigator.appCodeName + "</p>& ...
- 虚拟继承C++
C++中虚拟继承的概念 为了解决从不同途径继承来的同名的数据成员在内存中有不同的拷贝造成数据不一致问题,将共同基类设置为虚基类.这时从不同的路径继承过来的同名数据成员在内存中就只有一个拷贝,同一个函数 ...
- 2019/3/27 wen 数组排序