I have a problem with this exercise: Define a class that represent a circle. Constant defined class that holds the value of pi, and a variable defined in readonly holding the color of the circle. The possible colors are defined in enum. Variables defined class to hold the radius of the circle And functions that calculate the perimeter and area of the object. That's what I've done:
class Circle
{
public const double PI = 3.14;
public readonly enum color { Black, Yellow, Blue, Green };
int radius;
public Circle(string Color,int radius)
{
this.radius = radius;
}
}
I don't know how can I put the enum selection in the constructor. Thanks for helping.
public enum Color { Black, Yellow, Blue, Green };
class Circle
{
public const double PI = 3.14;
private Color _color;
int radius;
public Circle(int radius, Color color)
{
this.radius = radius;
this._color = color;
}
}
You can also pass string of color, but then you'll have to do Enum.Parse(type of enum, string value).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With