Я прочитал этот код:Что такое реализация List?
List<long> userIdList = new List<long>();
Но я подскочил к определению (использование VS2012) из List
(в System.Collections.Generic
), я нашел:
public class List<T> : IList<T>, ICollection<T>, IEnumerable<T>, IList, ICollection, IEnumerable
{
// Summary:
// Initializes a new instance of the System.Collections.Generic.List<T> class
// that is empty and has the default initial capacity.
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public List();
//
// Summary:
// Initializes a new instance of the System.Collections.Generic.List<T> class
// that contains elements copied from the specified collection and has sufficient
// capacity to accommodate the number of elements copied.
//
// Parameters:
// collection:
// The collection whose elements are copied to the new list.
//
// Exceptions:
// System.ArgumentNullException:
// collection is null.
public List(IEnumerable<T> collection);
//
// Summary:
// Initializes a new instance of the System.Collections.Generic.List<T> class
// that is empty and has the specified initial capacity.
//
// Parameters:
// capacity:
// The number of elements that the new list can initially store.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// capacity is less than 0.
[TargetedPatchingOptOut("Performance critical to inline across NGen image boundaries")]
public List(int capacity);
// Summary:
// Gets or sets the total number of elements the internal data structure can
// hold without resizing.
//
// Returns:
// The number of elements that the System.Collections.Generic.List<T> can contain
// before resizing is required.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// System.Collections.Generic.List<T>.Capacity is set to a value that is less
// than System.Collections.Generic.List<T>.Count.
//
// System.OutOfMemoryException:
// There is not enough memory available on the system.
public int Capacity { get; set; }
//
// Summary:
// Gets the number of elements actually contained in the System.Collections.Generic.List<T>.
//
// Returns:
// The number of elements actually contained in the System.Collections.Generic.List<T>.
public int Count { get; }
// Summary:
// Gets or sets the element at the specified index.
//
// Parameters:
// index:
// The zero-based index of the element to get or set.
//
// Returns:
// The element at the specified index.
//
// Exceptions:
// System.ArgumentOutOfRangeException:
// index is less than 0.-or-index is equal to or greater than System.Collections.Generic.List<T>.Count.
public T this[int index] { get; set; }
// Summary:
// Adds an object to the end of the System.Collections.Generic.List<T>.
//
// Parameters:
// item:
// The object to be added to the end of the System.Collections.Generic.List<T>.
// The value can be null for reference types.
public void Add(T item);
...
Это не интерфейс или абстрактный, но это Безразлично У меня есть тело функции (для любого метода в этом классе). Я знаю ArrayList
и LinkedList
, но для List
, я понятия не имею о его реализации.
Мой вопрос:
- Где реализация
List
? - Если
List
равноArrayList
или что-то в этом роде, почему .net позволит двум классам, которые равны функции, но другому имени? ЕслиList
не соответствует любому другому классу в .NET, то почему бы назвать его таким неоднозначным именем?
Класс Список является общим эквивалентом класса ArrayList. Он реализует общий интерфейс IList, используя массив, размер которого динамически увеличивается по мере необходимости.
Так что, я думаю, что это плохое имя ...
http://referencesource.microsoft.com/#mscorlib/system/collections/generic/list.cs,cf7f4095e4de7646 – MarcinJuraszek
Исходный код находится здесь: http://reflector.webtropy.com/default.aspx/Net/Net/3 @ 5 @ 50727 @ 3053/DEVDIV/depot/DevDiv/релизы/whidbey/netfxsp/ndp/clr/src/BCL/System/Collections/Generic/List @ cs/2/List @ cs - взято из http://stackoverflow.com/questions/14913640/which-algorithm-is-used-in-listt-to-dynamically-allocate-memory – Rob
Что заставляет вас сказать, что 'List' является двусмысленным именем? – Enigmativity