如何为表&LT; T&GT;在C#中实现的? [英] How is List<T> implemented in C#?
本文介绍了如何为表&LT; T&GT;在C#中实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在想调用的性能名单,其中,T&GT; .Indexof(项目)
。我不知道这是否是一个O(n)性能的顺序算法或为O(log(n))的性能二叉树??
I was thinking about the performance of calling List<T>.Indexof(item)
. I am not sure if it will be a O(n) performance for a sequential algorithm or O(log(n)) performance for a binary tree??
谢谢!
推荐答案
使用反射器的.NET,我们可以看到:
Using Reflector for .NET we can see:
public int IndexOf(T item)
{
return Array.IndexOf<T>(this._items, item, 0, this._size);
}
public static int IndexOf<T>(T[] array, T value, int startIndex, int count)
{
return EqualityComparer<T>.Default.IndexOf(array, value, startIndex, count);
}
internal virtual int IndexOf(T[] array, T value, int startIndex, int count)
{
int num = startIndex + count;
for (int i = startIndex; i < num; i++)
{
if (this.Equals(array[i], value))
return i;
}
return -1;
}
这篇关于如何为表&LT; T&GT;在C#中实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文