Quelle est la mise en œuvre de la Liste?

J'ai lu ce code:

List<long> userIdList = new List<long>();

Mais j'ai sauté à la définition(utiliser VS2012) de List (en System.Collections.Generic), j'ai trouvé:

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);
...

Ce n'est pas de l'Interface ou de l'Abstrait, mais il n'a pas de corps de la fonction(pour n'importe quelle méthode de la classe). Je sais ArrayList et LinkedList, mais pour List, je n'ai aucune idée à propos de sa mise en œuvre.

Ma question:

  1. Où est la mise en œuvre de List?
  2. Si List est égal à ArrayList ou quelque chose, pourquoi .net permet à deux classe qui est égale à la fonction mais nom différent? Si List n'est pas égal à tout autre classe .NET, alors pourquoi lui donner un nom ambigu?

MSDN unis:

La Liste de la classe est l'équivalent générique de la classe ArrayList. Il
met en œuvre les IList interface générique, en utilisant un tableau dont la taille
dynamique est augmenté selon les besoins.

Donc, je pense que c'est un mauvais nom...

  • referencesource.microsoft.com/#mscorlib/system/collections/...
  • Le code Source est ici: reflector.webtropy.com/default.aspx/Net/Net/3@5@50727@3053/... - prises à partir de stackoverflow.com/questions/14913640/...
  • Ce qui vous fait dire que List est un nom ambigu?
  • Peut-être que je suis habitué à Java.. En Java, la Liste est abstract, nous devons déclarer une mise en œuvre concrète de la Liste pour l'utiliser.
  • Java semble appeler ArrayList<E>. C'est le même que List<T>.
  • Mais ce n'en est pas ambigu. Est-il une autre raison pour laquelle vous pensez que c'est ambigu?
  • si c'est la version générique de System.Collections.ArrayList, je pense que c'est peut être mieux de nom, il GenericArrayList. Lorsque nous avons besoin d'un GenericLinkedList, ce qui devrait nous le nom? AnotherList?
  • Je vois. Vous avez un point, mais je pense que le problème, c'est que quelqu'un a été un peu simplet de l'appel de la non-générique liste ArrayList. Je pense qu'ils ont pensé qu'il n'était pas important de l'appel d'une liste par le nom du type de données.

InformationsquelleAutor Sayakiss | 2015-07-08