CSharp examples for System.Collections:IDictionary
Get Or Add from IDictionary
using System.Threading.Tasks; using System.Text; using System.Linq; using System.Collections.Generic; using System;/*from w ww . j a va2 s. c o m*/ public class Main{ public static TValue GetOrAdd<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key, Func<TKey, TValue> createValue) { TValue value; if (!source.TryGetValue(key, out value)) { source[key] = value = createValue(key); } return value; } }