c#类中含有数组,,应该如何输出

编写了一个圆类,其中设了一各圆心字段,用的是数组,现在想将数组的元素作为x,y坐标输出,如何编写

img

img

定义一个数组来做呗,像这样:

        (double x, double y)[] center = { (2, 3), (4, 5) };
        Circle c = new Circle(5, center);
        Console.WriteLine(c.ToString());
        Console.WriteLine($"周长: {c.Circumference()}, 面积: {c.Area()}");

要输出数组中的元素作为x,y坐标,可以使用循环遍历数组并输出每个元素。以下是示例代码:

using System;

class Program {
    static void Main(string[] args) {
        // 创建一个包含圆心点的数组
        int[] 圆圈 = { 1, 2, 3, 4, 5 };

        // 输出数组中的x,y坐标
        Console.WriteLine("圆圈的x坐标是:");
        foreach (int x in 圆圈) {
            Console.WriteLine(x);
        }

        Console.WriteLine("圆圈的y坐标是:");
        foreach (int y in 圆圈) {
            Console.WriteLine(y);
        }
    }
}

在这个例子中,我们创建了一个包含圆心点的数组,并使用循环遍历该数组,并输出每个元素的x和y坐标。输出结果如下:

圆圈的x坐标是:1
圆圈的y坐标是:2
圆圈的x坐标是:3
圆圈的y坐标是:4
圆圈的x坐标是:5

请注意,这种方法只适用于该数组的唯一元素是圆心点的情况。如果该数组包含多个圆心点,则可能需要使用其他技术来实现相同的功能。