Skip to content

Instantly share code, notes, and snippets.

@ViIvanov
Last active August 29, 2015 13:57
Show Gist options
  • Save ViIvanov/9533018 to your computer and use it in GitHub Desktop.
Save ViIvanov/9533018 to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Collections.ObjectModel;
internal static class Program
{
private static TValue GetValueOrDefault<TKey, TValue>(this IDictionary<TKey, TValue> source, TKey key) { return default(TValue); }
private static TValue GetValueOrDefault<TKey, TValue>(this IReadOnlyDictionary<TKey, TValue> source, TKey key) { return default(TValue); }
private static void Main() {
var dictionary = new Dictionary<int, int>();
var v1 = dictionary.GetValueOrDefault(0); // error CS0121: The call is ambiguous between the following methods or properties…
var readOnly = new ReadOnlyDictionary<int, int>(dictionary);
var v2 = readOnly.GetValueOrDefault(0); // error CS0121: The call is ambiguous between the following methods or properties…
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment