Created
December 18, 2017 11:06
-
-
Save alextercete/bab183136285122631b430d163c696ec to your computer and use it in GitHub Desktop.
Optional parameter unexpected behaviour
This file contains hidden or 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
using System; | |
using System.Linq; | |
namespace OptionalParameterUnexpectedBehaviour | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var numbers = Enumerable.Range(1, 5); | |
var powers = numbers.Select(Pow); | |
Console.WriteLine($"Expected: 1,4,9,16,25"); | |
Console.WriteLine($"Actual: {string.Join(',', powers)}"); // 1,2,9,64,625 | |
} | |
private static int Pow(int number, int power = 2) | |
{ | |
return (int) Math.Pow(number, power); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment