Looking at the docs for KeyedCollection
i read the following::
The KeyedCollection class provides both O(1) indexed retrieval and keyed retrieval that approaches O(1).
I do not fully understand what this means. I personally would think that indexed retrieval and keyed retrieval are the same since a dictionary indexes by keys. I feel a bit vague about the terms 'indexed retrieval' and 'keyed retrieval' altogether i suppose.
So what's the difference, and why is the complexion different?
Additional info:
I personally would like to use the keyedCollection
because I have a list that will be added to a lot. Now and then i need to fetch an item by an id - a Guid
and return some data. I also periodically will go through the list and delete any items i no longer use.
Sample;
/// <summary>
/// A collection of leases. Implements <see cref="KeyedCollection{TKey,TItem}"/> which is a dictionary-list hybrid.
/// </summary>
public class LeaseInfoCollection : KeyedCollection<Guid, LeaseInfo>
{
#region Construction and Destruction
/// <inheritdoc />
public LeaseInfoCollection()
{
}
/// <inheritdoc />
public LeaseInfoCollection(IEqualityComparer<Guid> comparer)
: base(comparer)
{
}
/// <inheritdoc />
public LeaseInfoCollection(IEqualityComparer<Guid> comparer, int dictionaryCreationThreshold)
: base(comparer, dictionaryCreationThreshold)
{
}
#endregion
#region Overrides of KeyedCollection<string,LeaseInfo>
/// <inheritdoc />
protected override Guid GetKeyForItem(LeaseInfo item)
{
return item.LeaseId;
}
#endregion
}