Skip to content

Instantly share code, notes, and snippets.

@alastairs
Created February 5, 2017 19:45
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 alastairs/2ad4f8625307c51dbdf932e830658691 to your computer and use it in GitHub Desktop.
Save alastairs/2ad4f8625307c51dbdf932e830658691 to your computer and use it in GitHub Desktop.
Express Yourself! Motivating Example
public int WhatDoIDo(int[] numbers)
{
return numbers.Count(i => i % 2 == 0)
}
public int WhatDoIDo(int[] numbers)
{
var count = 0;
foreach (var i in numbers)
{
if (i % 2 == 0)
{
count++;
}
}
return count;
}
public class public int WhatDoIDo(int[] numbers)
{
return numbers.Count(IsEven)
}
private static bool IsEven(int i)
{
return i % 2 == 0;
}
public int WhatDoIDo(int[] numbers)
{
return numbers.Count(i => i.IsEven());
}
public static class MathExtensions
{
public static bool IsEven(this int i)
{
return i % 2 == 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment