Skip to content

Common Dictionary

Ivan Kozhin edited this page Aug 24, 2020 · 4 revisions

1. GetValueOrDefault

TValue GetValueOrDefault<TKey, TValue>(
  IDictionary<TKey, TValue> target,
  TKey key,
  TValue defaultValue)

Tries to get the value by key. If the key is not presented in the dictionary it returns defaultValue.

2. AddOrUpdate

TValue AddOrUpdate<TKey, TValue>(
  IDictionary<TKey, TValue> target,
  TKey key,
  Func<TKey, TValue, TValue> updateFunc,
  TValue defaultValue)

Adds a key/value pair to the IDictionary{TKey,TValue} if the key does not already exist, or updates a key/value pair in the IDictionary{TKey,TValue} if the key already exists. The default value will be used if the key is missed to the IDictionary{TKey,TValue}.

3. GetValueOrDefault

string GetValueOrDefault(NameValueCollection target, string key, string defaultValues)

Tries to get the value in NameValueCollection. If a value with the specified key does not exist it will return defaultValues. It can be used for application settings.

4. GetValuesOrDefault

string[] GetValuesOrDefault(NameValueCollection target, string key, string[] defaultValues)

Tries to get the values in NameValueCollection. If a value with the specified key does not exist it will return defaultValues. It can be used for application settings.

Clone this wiki locally