Click or drag to resize

DictionaryListTKey, TValue Class

Represents a sorted dictionary style list that supports IList.
Inheritance Hierarchy
SystemObject
  GSF.CollectionsDictionaryListTKey, TValue

Namespace: GSF.Collections
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public class DictionaryList<TKey, TValue> : IList<KeyValuePair<TKey, TValue>>, 
	ICollection<KeyValuePair<TKey, TValue>>, IEnumerable<KeyValuePair<TKey, TValue>>, 
	IEnumerable, IDictionary<TKey, TValue>
View Source

Type Parameters

TKey
Generic key type.
TValue
Generic value type.

The DictionaryListTKey, TValue type exposes the following members.

Constructors
 NameDescription
Public methodDictionaryListTKey, TValue Creates a new DictionaryListTKey, TValue.
Top
Properties
 NameDescription
Public propertyCount Gets the number of elements contained in the DictionaryListTKey, TValue.
Public propertyIsReadOnly Gets a value indicating whether the DictionaryListTKey, TValue is read-only.
Public propertyItemTKey Gets or sets the element with the specified key.
Public propertyItemInt32 Gets or sets the element at the specified index.
Public propertyKeys Gets an ICollectionT containing the keys of the IDictionaryTKey, TValue.
Public propertyValues Gets an ICollectionT containing the values in the IDictionaryTKey, TValue.
Top
Methods
 NameDescription
Public methodAdd(KeyValuePairTKey, TValue) Adds an item to the DictionaryListTKey, TValue.
Public methodAdd(TKey, TValue) Adds an element with the provided key and value to the DictionaryListTKey, TValue.
Public methodClear Removes all items from the DictionaryListTKey, TValue.
Public methodContains Determines whether the DictionaryListTKey, TValue contains a specific value.
Public methodContainsKey Determines whether the DictionaryListTKey, TValue contains an element with the specified key.
Public methodContainsValue Determines whether the DictionaryListTKey, TValue contains a specific value.
Public methodCopyTo Copies the elements of the DictionaryListTKey, TValue to an Array, starting at a particular index.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object)
Public methodGetEnumerator Returns an enumerator that iterates through the collection.
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Public methodIndexOf Determines the index of a specific item in the DictionaryListTKey, TValue.
Public methodIndexOfKey Searches for the specified key and returns the zero-based index within the entire DictionaryListTKey, TValue.
Public methodIndexOfValue Searches for the specified value and returns the zero-based index of the first occurrence within the entire DictionaryListTKey, TValue.
Public methodInsert Inserts an item to the DictionaryListTKey, TValue at the specified index.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodRemove(TKey) Removes the element with the specified key from the DictionaryListTKey, TValue.
Public methodRemove(KeyValuePairTKey, TValue) Removes the first occurrence of a specific object from the DictionaryListTKey, TValue.
Public methodRemoveAt Removes the DictionaryListTKey, TValue item at the specified index.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Public methodTryGetValue Gets the value associated with the specified key.
Top
Extension Methods
 NameDescription
Public Extension MethodAddRangeKeyValuePairTKey, TValue Adds the specified items to the collection.
(Defined by CollectionExtensions)
Public Extension MethodAllParallelKeyValuePairTKey, TValue Determines whether all elements of a sequence satisfy a condition with each item being tested in parallel.
(Defined by CollectionExtensions)
Public Extension MethodDistinctByKeyValuePairTKey, TValue, TKey Returns only the elements whose keys are distinct.
(Defined by CollectionExtensions)
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetRangeKeyValuePairTKey, TValue Returns elements in the specified range from the collection.
(Defined by CollectionExtensions)
Public Extension MethodIndexOfKeyValuePairTKey, 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)
Public Extension MethodLoadDelimitedStringKeyValuePairTKey, TValueAppends items parsed from delimited string, created with ToDelimitedString, using the default delimiter ("|") into the given list.
(Defined by CollectionExtensions)
Public Extension MethodLoadDelimitedStringKeyValuePairTKey, TValueAppends items parsed from delimited string, created with ToDelimitedString, into the given list.
(Defined by CollectionExtensions)
Public Extension MethodLoadDelimitedStringKeyValuePairTKey, TValueAppends items parsed from delimited string, created with ToDelimitedString, into the given list.
(Defined by CollectionExtensions)
Public Extension MethodMajorityKeyValuePairTKey, TValue Returns the majority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMajorityKeyValuePairTKey, TValue Returns the majority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMajorityByKeyValuePairTKey, TValue, TKey Returns the majority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMajorityByKeyValuePairTKey, TValue, TKey Returns the majority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMaxKeyValuePairTKey, TValueReturns the largest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMaxKeyValuePairTKey, TValueReturns the largest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMaxByKeyValuePairTKey, TValue, TKeySelects the largest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMedianKeyValuePairTKey, TValue Gets the median item(s) from an enumeration, i.e., one return item for odd lengths, two for even lengths.
(Defined by CollectionExtensions)
Public Extension MethodMiddleKeyValuePairTKey, TValue Gets the middle item(s) from an enumeration, i.e., one return item for odd lengths, two for even lengths.
(Defined by CollectionExtensions)
Public Extension MethodMinKeyValuePairTKey, TValueReturns the smallest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMinKeyValuePairTKey, TValueReturns the smallest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMinByKeyValuePairTKey, TValue, TKeySelects the smallest item from the enumeration.
(Defined by CollectionExtensions)
Public Extension MethodMinorityKeyValuePairTKey, TValue Returns the minority value in the collection, or default type value if no item represents the minority.
(Defined by CollectionExtensions)
Public Extension MethodMinorityKeyValuePairTKey, TValue Returns the minority value in the collection, or defaultValue if no item represents the minority.
(Defined by CollectionExtensions)
Public Extension MethodMinorityByKeyValuePairTKey, TValue, TKey Returns the minority value in the collection, or default type value if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodMinorityByKeyValuePairTKey, TValue, TKey Returns the minority value in the collection, or defaultValue if no item represents the majority.
(Defined by CollectionExtensions)
Public Extension MethodScrambleKeyValuePairTKey, TValue Rearranges all the elements in the list into a highly-random order.
(Defined by CollectionExtensions)
Public Extension MethodScrambleKeyValuePairTKey, TValue Rearranges all the elements in the list into a repeatable pseudo-random order.
(Defined by CollectionExtensions)
Public Extension MethodStandardDeviationKeyValuePairTKey, TValue Computes the standard deviation over a sequence of Double values.
(Defined by NumericalAnalysisExtensions)
Public Extension MethodStandardDeviationKeyValuePairTKey, TValue Computes the standard deviation over a sequence of Decimal values.
(Defined by NumericalAnalysisExtensions)
Public Extension MethodStandardDeviationKeyValuePairTKey, TValue Computes the standard deviation over a sequence of Single values.
(Defined by NumericalAnalysisExtensions)
Public Extension MethodToDelimitedStringKeyValuePairTKey, TValueConverts an enumeration to a string, using the default delimiter ("|") that can later be converted back to a list using LoadDelimitedString.
(Defined by CollectionExtensions)
Public Extension MethodToDelimitedStringKeyValuePairTKey, TValueConverts an enumeration to a string that can later be converted back to a list using LoadDelimitedString.
(Defined by CollectionExtensions)
Public Extension MethodToDelimitedStringKeyValuePairTKey, TValueConverts an enumeration to a string that can later be converted back to a list using LoadDelimitedString.
(Defined by CollectionExtensions)
Public Extension MethodToPagedListKeyValuePairTKey, TValue Gets a PagedListT to paginate source enumeration for a given page and specified pageSize.
(Defined by CollectionExtensions)
Public Extension MethodUnscrambleKeyValuePairTKey, TValue Rearranges all the elements in the list previously scrambled with ScrambleTSource(IListTSource, Int32) back into their original order.
(Defined by CollectionExtensions)
Public Extension MethodUpdateRangeKeyValuePairTKey, TValue Updates collection starting at the index with the specified items.
(Defined by CollectionExtensions)
Top
Remarks

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.

See Also