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绕过的文章,我觉得这种老生常 谈的话题 ...
随机推荐
- python 爬取qidian某一页全部小说
本文纯粹用于技术练习,请勿用作非法途径 import re import urllib.request from bs4 import BeautifulSoup import time url= ...
- Python全栈-异常处理
一.异常 1.异常的定义 异常是错误发生的信号,程序一旦出错就会抛出错误信息,如果不及时处理就会程序就会随之停止运行 异常有三部分组成: 1)异常类型 2)异常追踪 3)异常的值 2.异常的分类 1) ...
- ModuleNotFoundError: No module named '_pydevd_bundle.pydevd_cython' error on debug
现象:pycharm调试代码出现错误:ModuleNotFoundError: No module named '_pydevd_bundle.pydevd_cython' error on debu ...
- Vue系列之 => 使用第三方animated.css动画
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 怎么查 ODBC Driver for SQL Server
1)进入服务器,找到SQL Server 2016 Configuration... ,点进去就好了 2)
- linux常用命令:rm 命令
昨天学习了创建文件和目录的命令mkdir ,今天学习一下linux中删除文件和目录的命令: rm命令.rm是常用的命令,该命令的功能为删除一个目录中的一个或多个文件或目录,它也可以将某个目录及其下的所 ...
- 设置 DNS,防止 DNS 污染,清除 DNS 缓存ipconfig /flushdns
设置 DNS,防止 DNS 污染选中“使用下面的 DNS 服务器地址”,“首选 DNS 服务器”中填写 8.8.8.8,“备用 DNS 服务器”中填写 8.8.4.4,然后点击“确定”按钮清除 DNS ...
- 使用Fiddler测试WebApi接口
Fiddler是好用的WebApi调试工具之一,它能记录所有客户端和服务器的http和https请求,允许你监视,设置断点,甚至修改输入输出数据,Fiddler 是以代理web服务器的形式工作的,使用 ...
- Autel MaxiSys Pro MS908P Software Update Gudie
This article aims to guide on how to update software for Autel MaxiSys Pro. (Suitable for MaxiDiag E ...
- mysql安装登录
接下来就开始安装mysql 下载地址:http://dev.mysql.com/downloads/mysql/ 选择 dmg格式 下载完毕后,双击打开dmg文件,双击 “mysql-5.7.9-o ...