Show / Hide Table of Contents
  • MaybeSharp
    • Maybe<T>
      • As
      • Bind
      • Cast
      • CompareTo
      • Equality
      • Equals
      • Explicit
      • GetHashCode
      • GreaterThan
      • GreaterThanOrEqual
      • HasValue
      • Implicit
      • Inequality
      • IsEmpty
      • LessThan
      • LessThanOrEqual
      • Maybe
      • Nothing
      • ToString
      • Value
  • MaybeSharp.Extensions
    • MaybeDictionaryExtensions
      • TryGetValue
    • MaybeExtensions
      • Coalesce
      • Or
      • Select
      • SelectMany
      • SelectNonempty
      • ToNullable
      • ValueOr
      • ValueOrException
      • WhenNothing
      • WhenSomething
      • Where
    • MaybeStringExtensions
      • TryParseBoolean
      • TryParseByte
      • TryParseChar
      • TryParseDateTime
      • TryParseDateTimeOffset
      • TryParseDecimal
      • TryParseDouble
      • TryParseInt
      • TryParseInt16
      • TryParseInt64
      • TryParseSingle
    • NullableExtensions
      • ToMaybe

Method TryGetValue

TryGetValue<TKey, TValue>(IDictionary<TKey, TValue>, TKey)

Attempts to retrieve a value with the sepcified key from the given collection and returns the result as a Maybe<T>. If the key is not found, an empty maybe is returned.

Declaration
public static Maybe<TValue> TryGetValue<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key)
Parameters
Type Name Description
IDictionary<TKey, TValue> source

The dictionary to retrieve a value from.

TKey key

The key of the value to retrieve.

Returns
Type Description
Maybe<TValue>

A Maybe<T> containing the retrieved value, or an empty Maybe<T> if the key was not found in the dictionary.

Type Parameters
Name Description
TKey

The type of key stored in the dictionary.

TValue

The type of value stored in the dictionary.

Exceptions
Type Condition
System.ArgumentNullException

Thrhwon if source is null.

Back to top Copyright (c) 2017 Troy Willmot