C#
public interface Shape
{
public float area();
}
struct Rectangle(float width, float length) : Shape
{
float width = width;
float length = length;
public float area()
{
return width * length;
}
}
struct Circle(float radius) : Shape
{
float radius = radius;
public float area()
{
return (float)Math.Pow(Math.PI * radius, 2);
}
}
class Program
{
public static float calcualteArea(Shape s)
{
return s.area();
}
public static void Main()
{
Rectangle r = new(3, 4);
Circle c = new(5);
Shape[] shapes = [r, c]; // where do these values exist?
Console.WriteLine(calcualteArea(shapes[0]));
Console.WriteLine(calcualteArea(shapes[1]));
}
}
C#
public interface Shape
{
public float area();
}
struct Rectangle(float width, float length) : Shape
{
float width = width;
float length = length;
public float area()
{
return width * length;
}
}
struct Circle(float radius) : Shape
{
float radius = radius;
public float area()
{
return (float)Math.Pow(Math.PI * radius, 2);
}
}
class Program
{
public static float calcualteArea(Shape s)
{
return s.area();
}
public static void Main()
{
Rectangle r = new(3, 4);
Circle c = new(5);
Shape[] shapes = [r, c]; // where do these values exist?
Console.WriteLine(calcualteArea(shapes[0]));
Console.WriteLine(calcualteArea(shapes[1]));
}
}