它更快的名单,其中,T>卸下摆臂(T)或列表< T> .RemoveAt(int)方法? [英] Is it faster the List<T>.Remove(T) or List<T>.RemoveAt(int) method?

查看:117
本文介绍了它更快的名单,其中,T>卸下摆臂(T)或列表< T> .RemoveAt(int)方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它更快的List.Remove(T)或.NET集合List.RemoveAt(int)方法?这是一个速度值类型和引用类型不同?

Is it faster the List.Remove(T) or List.RemoveAt(int) method in .NET collections? Is speed different for value types or reference types?

谢谢

阿尔贝托

推荐答案

List.Remove(T)使用的IndexOf和RemoveAt(INT)在其实施。所以List.RemoveAt(INT)更快。

List.Remove(T) uses IndexOf and RemoveAt(int) in its implementation. So List.RemoveAt(int) is faster.

public bool Remove(T item)
{
    int index = this.IndexOf(item);
    if (index >= 0)
    {
        this.RemoveAt(index);
        return true;
    }
    return false;
}

这篇关于它更快的名单,其中,T>卸下摆臂(T)或列表< T> .RemoveAt(int)方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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