首页 > 解决方案 > 尝试获取数组的第一个元素,然后将其返回给 main 方法

问题描述

代码无法编译,试图找到一种方法来获取数组的第一个元素并将其返回给 main 方法

using System;

namespace ProgramExercise10_2
{

    class PhotoDemo
    {
        class Photo
        {
            protected double[] price = { 3.99, 5.99, 9.99 };

            public photoPrice(int width, int height)
            {
                Console.Write("Enter photo width: ");
                width = Convert.ToInt32(Console.ReadLine());
                Console.Write("Enter photo height: ");
                height = Convert.ToInt32(Console.ReadLine());

                if ( width == 8 && height == 10)
                {
                    double[] _price = price[1];
                    return _price;
                }
            }
        }
    }
    class Program
    {
        static void Main(string[] args)
        {

        }
    }
}

无法将 double 隐式转换为 double[]

标签: c#

解决方案


 double[] _price = price[1]; 

应该

double _price = price[1];

推荐阅读