Skip to content

Instantly share code, notes, and snippets.

@alextercete
Created December 18, 2017 11:06
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 alextercete/bab183136285122631b430d163c696ec to your computer and use it in GitHub Desktop.
Save alextercete/bab183136285122631b430d163c696ec to your computer and use it in GitHub Desktop.
Optional parameter unexpected behaviour
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