Skip to content

M_CodeJam_Collections_DictionaryExtensions_GetValueOrDefault__3_11

Andrew Koryavchenko edited this page Jun 17, 2018 · 5 revisions

DictionaryExtensions.GetValueOrDefault(TKey, TValue, TResult) Method (IReadOnlyDictionary(TKey, TValue), TKey, Func(TKey, TValue, TResult), TResult)

Returns value associated with key, or defaultValue if key does not exists in dictionary

Namespace: CodeJam.Collections
Assembly: CodeJam (in CodeJam.dll) Version: 2.1.0.0

Syntax

C#

public static TResult GetValueOrDefault<TKey, TValue, TResult>(
	this IReadOnlyDictionary<TKey, TValue> dictionary,
	TKey key,
	Func<TKey, TValue, TResult> resultSelector,
	TResult defaultValue
)

VB

<ExtensionAttribute>
Public Shared Function GetValueOrDefault(Of TKey, TValue, TResult) ( 
	dictionary As IReadOnlyDictionary(Of TKey, TValue),
	key As TKey,
	resultSelector As Func(Of TKey, TValue, TResult),
	defaultValue As TResult
) As TResult

F#

[<ExtensionAttribute>]
static member GetValueOrDefault : 
        dictionary : IReadOnlyDictionary<'TKey, 'TValue> * 
        key : 'TKey * 
        resultSelector : Func<'TKey, 'TValue, 'TResult> * 
        defaultValue : 'TResult -> 'TResult 

Parameters

 

dictionary
Type: System.Collections.Generic.IReadOnlyDictionary(TKey, TValue)
The dictionary.
key
Type: TKey
The key.
resultSelector
Type: System.Func(TKey, TValue, TResult)
Function to select result.
defaultValue
Type: TResult
Default value.

Type Parameters

 

TKey
The type of the key.
TValue
The type of the value.
TResult
Result type.

Return Value

Type: TResult
Value, associated with the key, or defaultValue if key does not exists in dictionary

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type IReadOnlyDictionary(TKey, 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

Reference

DictionaryExtensions Class
GetValueOrDefault Overload
CodeJam.Collections Namespace

Clone this wiki locally