Created
February 5, 2017 19:45
-
-
Save alastairs/2ad4f8625307c51dbdf932e830658691 to your computer and use it in GitHub Desktop.
Express Yourself! Motivating Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int WhatDoIDo(int[] numbers) | |
{ | |
return numbers.Count(i => i % 2 == 0) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public int WhatDoIDo(int[] numbers) | |
{ | |
var count = 0; | |
foreach (var i in numbers) | |
{ | |
if (i % 2 == 0) | |
{ | |
count++; | |
} | |
} | |
return count; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class public int WhatDoIDo(int[] numbers) | |
{ | |
return numbers.Count(IsEven) | |
} | |
private static bool IsEven(int i) | |
{ | |
return i % 2 == 0; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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