Skip to content

Instantly share code, notes, and snippets.

@JayBazuzi
Last active January 2, 2016 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JayBazuzi/8227902 to your computer and use it in GitHub Desktop.
Save JayBazuzi/8227902 to your computer and use it in GitHub Desktop.
new Dictionary<int, string>
{
{ 3, "Fizz"},
{ 5, "Buzz"},
{15, "FizzBuzz"},
}
.Where(item => i % item.Key == 0)
.Select(item => item.Value)
.LastOrDefault() ?? i.ToString();
new Dictionary<int, string>
{
{ 3, "Fizz"},
{ 5, "Buzz"},
{15, "FizzBuzz"},
}
.Where(item => i % item.Key == 0)
.Select(item => item.Value)
.LastOr(i.ToString());
static class _
{
public static T LastOr<T>(this IEnumerable<T> s, T t) where T : class { return s.LastOrDefault() ?? t; }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment