Dictionary
|
public class DictionaryList<TKey, TValue> : IList<KeyValuePair<TKey, TValue>>, ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, IEnumerable, IDictionary<TKey, TValue>
The DictionaryListTKey, TValue type exposes the following members.
Name | Description | |
---|---|---|
DictionaryListTKey, TValue | Creates a new DictionaryListTKey, TValue. |
Name | Description | |
---|---|---|
Count | Gets the number of elements contained in the DictionaryListTKey, TValue. | |
IsReadOnly | Gets a value indicating whether the DictionaryListTKey, TValue is read-only. | |
ItemTKey | Gets or sets the element with the specified key. | |
ItemInt32 | Gets or sets the element at the specified index. | |
Keys | Gets an ICollectionT containing the keys of the IDictionaryTKey, TValue. | |
Values | Gets an ICollectionT containing the values in the IDictionaryTKey, TValue. |
Name | Description | |
---|---|---|
Add(KeyValuePairTKey, TValue) | Adds an item to the DictionaryListTKey, TValue. | |
Add(TKey, TValue) | Adds an element with the provided key and value to the DictionaryListTKey, TValue. | |
Clear | Removes all items from the DictionaryListTKey, TValue. | |
Contains | Determines whether the DictionaryListTKey, TValue contains a specific value. | |
ContainsKey | Determines whether the DictionaryListTKey, TValue contains an element with the specified key. | |
ContainsValue | Determines whether the DictionaryListTKey, TValue contains a specific value. | |
CopyTo | Copies the elements of the DictionaryListTKey, TValue to an Array, starting at a particular index. | |
Equals | Determines whether the specified object is equal to the current object. (Inherited from Object) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object) | |
GetEnumerator | Returns an enumerator that iterates through the collection. | |
GetHashCode | Serves as the default hash function. (Inherited from Object) | |
GetType | Gets the Type of the current instance. (Inherited from Object) | |
IndexOf | Determines the index of a specific item in the DictionaryListTKey, TValue. | |
IndexOfKey | Searches for the specified key and returns the zero-based index within the entire DictionaryListTKey, TValue. | |
IndexOfValue | Searches for the specified value and returns the zero-based index of the first occurrence within the entire DictionaryListTKey, TValue. | |
Insert | Inserts an item to the DictionaryListTKey, TValue at the specified index. | |
MemberwiseClone | Creates a shallow copy of the current Object. (Inherited from Object) | |
Remove(TKey) | Removes the element with the specified key from the DictionaryListTKey, TValue. | |
Remove(KeyValuePairTKey, TValue) | Removes the first occurrence of a specific object from the DictionaryListTKey, TValue. | |
RemoveAt | Removes the DictionaryListTKey, TValue item at the specified index. | |
ToString | Returns a string that represents the current object. (Inherited from Object) | |
TryGetValue | Gets the value associated with the specified key. |
Name | Description | |
---|---|---|
AddRangeKeyValuePairTKey, TValue |
Adds the specified items to the collection.
(Defined by CollectionExtensions) | |
AllParallelKeyValuePairTKey, TValue |
Determines whether all elements of a sequence satisfy a condition with each item being tested in parallel.
(Defined by CollectionExtensions) | |
DistinctByKeyValuePairTKey, TValue, TKey |
Returns only the elements whose keys are distinct.
(Defined by CollectionExtensions) | |
GetEnumValueOrDefault |
Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) | |
GetEnumValueOrDefaultT |
Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions) | |
GetRangeKeyValuePairTKey, TValue |
Returns elements in the specified range from the collection.
(Defined by CollectionExtensions) | |
IndexOfKeyValuePairTKey, TValue |
Returns the index of the first element of the sequence that satisfies a condition or -1 if no such element is found.
(Defined by CollectionExtensions) | |
LoadDelimitedStringKeyValuePairTKey, TValue | Appends items parsed from delimited string, created with ToDelimitedString, using the default
delimiter ("|") into the given list. (Defined by CollectionExtensions) | |
LoadDelimitedStringKeyValuePairTKey, TValue | Appends items parsed from delimited string, created with ToDelimitedString, into the given list. (Defined by CollectionExtensions) | |
LoadDelimitedStringKeyValuePairTKey, TValue | Appends items parsed from delimited string, created with ToDelimitedString, into the given list. (Defined by CollectionExtensions) | |
MajorityKeyValuePairTKey, TValue |
Returns the majority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions) | |
MajorityKeyValuePairTKey, TValue |
Returns the majority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions) | |
MajorityByKeyValuePairTKey, TValue, TKey |
Returns the majority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions) | |
MajorityByKeyValuePairTKey, TValue, TKey |
Returns the majority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions) | |
MaxKeyValuePairTKey, TValue | Returns the largest item from the enumeration. (Defined by CollectionExtensions) | |
MaxKeyValuePairTKey, TValue | Returns the largest item from the enumeration. (Defined by CollectionExtensions) | |
MaxByKeyValuePairTKey, TValue, TKey | Selects the largest item from the enumeration. (Defined by CollectionExtensions) | |
MedianKeyValuePairTKey, TValue |
Gets the median item(s) from an enumeration, i.e., one return item for odd lengths, two for even lengths.
(Defined by CollectionExtensions) | |
MiddleKeyValuePairTKey, TValue |
Gets the middle item(s) from an enumeration, i.e., one return item for odd lengths, two for even lengths.
(Defined by CollectionExtensions) | |
MinKeyValuePairTKey, TValue | Returns the smallest item from the enumeration. (Defined by CollectionExtensions) | |
MinKeyValuePairTKey, TValue | Returns the smallest item from the enumeration. (Defined by CollectionExtensions) | |
MinByKeyValuePairTKey, TValue, TKey | Selects the smallest item from the enumeration. (Defined by CollectionExtensions) | |
MinorityKeyValuePairTKey, TValue |
Returns the minority value in the collection, or default type value if no item represents the minority.
(Defined by CollectionExtensions) | |
MinorityKeyValuePairTKey, TValue |
Returns the minority value in the collection, or defaultValue if no item represents the minority.
(Defined by CollectionExtensions) | |
MinorityByKeyValuePairTKey, TValue, TKey |
Returns the minority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions) | |
MinorityByKeyValuePairTKey, TValue, TKey |
Returns the minority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions) | |
ScrambleKeyValuePairTKey, TValue |
Rearranges all the elements in the list into a highly-random order.
(Defined by CollectionExtensions) | |
ScrambleKeyValuePairTKey, TValue |
Rearranges all the elements in the list into a repeatable pseudo-random order.
(Defined by CollectionExtensions) | |
StandardDeviationKeyValuePairTKey, TValue |
Computes the standard deviation over a sequence of Double values.
(Defined by NumericalAnalysisExtensions) | |
StandardDeviationKeyValuePairTKey, TValue |
Computes the standard deviation over a sequence of Decimal values.
(Defined by NumericalAnalysisExtensions) | |
StandardDeviationKeyValuePairTKey, TValue |
Computes the standard deviation over a sequence of Single values.
(Defined by NumericalAnalysisExtensions) | |
ToDelimitedStringKeyValuePairTKey, TValue | Converts an enumeration to a string, using the default delimiter ("|") that can later be
converted back to a list using LoadDelimitedString. (Defined by CollectionExtensions) | |
ToDelimitedStringKeyValuePairTKey, TValue | Converts an enumeration to a string that can later be converted back to a list using
LoadDelimitedString. (Defined by CollectionExtensions) | |
ToDelimitedStringKeyValuePairTKey, TValue | Converts an enumeration to a string that can later be converted back to a list using
LoadDelimitedString. (Defined by CollectionExtensions) | |
ToPagedListKeyValuePairTKey, TValue |
Gets a PagedListT to paginate source enumeration for
a given page and specified pageSize.
(Defined by CollectionExtensions) | |
UnscrambleKeyValuePairTKey, TValue |
Rearranges all the elements in the list previously scrambled with ScrambleTSource(IListTSource, Int32) back into their original order.
(Defined by CollectionExtensions) | |
UpdateRangeKeyValuePairTKey, TValue |
Updates collection starting at the index with the specified items.
(Defined by CollectionExtensions) |
Have you ever needed the quick look-up feature on a Dictionary (e.g., Hashtable), but ended up missing the indexed or sequential access like you have in a list? You may have wondered why the .NET dictionary class doesn’t implement the IList interface which allows this. The reason IDictionary implementations do not normally implement the IList interface is because of ambiguity that is caused when implementing an integer key. For example, if you created a dictionary style class with a key of type "Integer" that actually did implement IList(Of T), you would not be able to access items in the IList interface by index without "casting" the class as IList. This is because the Item property in both the IDictionary and IList would have the same parameters. Note, however, that generics in .NET 2.0 gladly allow a class to implement both IDictionary and IList (even specifying as Integer as the key) so long you as you are happy knowing that the compiler will choose if you access your items by index or key. Given that caveat, there are many times when you need a dictionary style collection but also desire an IList implementation so the class can be used in other ways without conversion. As a result of these needs, we’ve added a generic class to code library called a DictionaryList -- which is essentially just a sorted dictionary style list (i.e., SortedList) that implements the IList(Of T) interface (specifically as IList(Of KeyValuePair(Of TKey, TValue))). You will find all of your convenient expected methods related to both dictionaries and lists; that is, you can look-up items by key or by index. The class works perfectly for any non-Integer based key (e.g., String, custom class, etc.) -- note that specifying an Integer as the key for the class won’t cause an error, but it also will not be very useful. However, you can specify the key for your DictionaryList as a "Long," which allows you to use long integers for keyed look-ups and regular integers for indexed access--the best of both worlds! In summary, I would not change your programming habits to start using this for "my collection for everything," as nothing comes for free; however, if you have a need for a "hybrid" collection class, this fits the bill.
Important note about using an "Integer" as the key for this class: IDictionary implementations do not normally implement the IList interface because of ambiguity that is caused when implementing an integer key. For example, if you implement this class with a key of type "Integer" you will not be able to access items in the queue by index without "casting" the class as IList. This is because the Item property in both the IDictionary and IList would have the same parameters.
Note that prior to the addition of Generics in .NET, the class that performed a similar function was the "NameObjectCollectionBase" in the System.Collections.Specialized namespace which specifically allowed item access by either key or by index. This class is similar in function but instead is a generic class allowing use with any strongly typed key or value.