I have a bit freetime, so started to fiddle a bit around with lambda expressions in C#, just for the sake of learning something new. So I started with a simple square function:
Func<int, int> square = x => x * x;
Which worked as I expected. Next I tried something like this:
Func<int, int> cube = x => x * x * x;
Func<int, int> pow4 = x => square(x) * square(x);
Which also worked like expected. Then I got curious and wanted to do something like this:
Func<int, int, int> pow = (x,y) => ... // multiply x with itself, y-times ;
I know, there are cases like y = 0 to care about, recursive algorithms to do this or use Math.pow(). So my question is: is it possible calculating the power of an integer by only using lambda expressions? How does it look like?
Thanks in advance.