Skip to content

Instantly share code, notes, and snippets.

@grzesiek-galezowski
Created July 27, 2021 19:43
Show Gist options
  • Save grzesiek-galezowski/419892d5cd6e4c838ebe6240f5c91529 to your computer and use it in GitHub Desktop.
Save grzesiek-galezowski/419892d5cd6e4c838ebe6240f5c91529 to your computer and use it in GitHub Desktop.
class C1
{
[Test]
public void METHOD()
{
var lookupValue1 = Lookup(new Dictionary<string, string?>(), "a");
var lookupValue2 = Lookup(new Dictionary<string, string>(), "a");
}
public LookupValue<TV> Lookup<TK, TV>(Dictionary<TK, TV?> d, TK key)
where TK : notnull
where TV : notnull
{
if (d.TryGetValue(key, out var result))
{
return new LookupValue<TV>(result);
}
else
{
return new LookupValue<TV>(default);
}
}
public record LookupValue<T>(T? Value) where T : notnull;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment