Click or drag to resize

CollectionExtensionsGetOrDefaultTKey, TValue(IDictionaryTKey, TValue, TKey, FuncTKey, TValue) Method

Attempts to get the value for the given key and returns the default value instead if the key does not exist in the IDictionaryTKey, TValue.

Namespace: GSF.Collections
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public static TValue GetOrDefault<TKey, TValue>(
	this IDictionary<TKey, TValue> dictionary,
	TKey key,
	Func<TKey, TValue> defaultValueFactory
)
View Source

Parameters

dictionary  IDictionaryTKey, TValue
The dictionary to check for the given key.
key  TKey
The key to be checked for the existence of a value.
defaultValueFactory  FuncTKey, TValue
The function used to generate the default value if no value exists for the given key.

Type Parameters

TKey
The type of the keys in the dictionary.
TValue
The type of the values in the dictionary.

Return Value

TValue
The value of the key in the dictionary or the default value if no such value exists.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IDictionaryTKey, TValue. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
See Also