C# linq扩展方法ElementAt的性能

C# linq扩展方法ElementAt的性能,c#,.net,collections,polymorphism,linq-extensions,C#,.net,Collections,Polymorphism,Linq Extensions,Enumerable.ElementAtTSource方法的MSDN库条目显示 如果源的类型实现 IList,则使用该实现 在指定的位置获取元素 指数否则,此方法将获得 指定的元素 假设我们有以下示例: ICollection<int> col = new List<int>() { /* fill with items */ }; IList<int> list = new List<int>() { /* fil

Enumerable.ElementAtTSource方法的MSDN库条目显示

如果源的类型实现 IList,则使用该实现 在指定的位置获取元素 指数否则,此方法将获得 指定的元素

假设我们有以下示例:

        ICollection<int> col = new List<int>() { /* fill with items */ };
        IList<int> list = new List<int>() { /* fill with items */ };

        col.ElementAt(10000000);
        list.ElementAt(10000000);
在执行上有什么不同吗?或者ElementAt是否认识到col也实现了IList,尽管它只声明为ICollection


感谢

变量本身的类型与ElementAt方法无关-就它而言,它只声明为IEnumerable,因为这就是参数类型。两个调用都将绑定到同一个扩展方法


这是在ElementAt中测试的对象的执行时间类型。

变量本身的类型与ElementAt方法无关-就其而言,它只声明为IEnumerable,因为这就是参数类型。两个调用都将绑定到同一个扩展方法


这是在ElementAt中测试的对象的执行时间类型。

否,为什么会有差异。ElementAt是IEnumerable的扩展方法。这种情况下不存在多态性。

不,为什么会有差异。ElementAt是IEnumerable的扩展方法。在这种情况下没有多态性