Wednesday, August 27, 2014

How to calculate the circumference of a circle based on the following Circle class?

Hi Rich,


you can do it like this with a lambda-expression:



Circle cir = new Circle();
double circ = cir.Calculate((radius) => 2 * Math.PI * radius);

But note that the radius-field is 0 by default. I tried it with 5 like this:



public sealed class Circle
{
private double radius = 5;

public double Calculate(Func<double, double> op)
{
return op(radius);
}
}



I got the correct result of 31.4...


Have fun.




Thomas Claudius Huber



"If you can't make your app run faster, make it at least look & feel extremly fast"



My latest Pluralsight-course: Windows Store Apps - Data Binding in Depth



twitter: @thomasclaudiush

homepage: http://ift.tt/1fArvuE

author of: ultimate Windows Store Apps handbook | ultimate WPF handbook | ultimate Silverlight handbook


No comments:

Post a Comment