c# - 尝试获取数组的第一个元素,然后将其返回给 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[]
解决方案
double[] _price = price[1];
应该
double _price = price[1];
推荐阅读
- python - 通过 Pinata API 和 python 固定目录
- java - 在 DevEco 的预览器中更改文本的语言
- sql - 获取需要与其他列不同的值的列的总和
- python - JupyterHub 在运行 Python Telegram Bot 时睡着了
- python - Check if all values of a column are equal in PySpark Dataframe
- hibernate - 嵌套属性中具有顺序参数的 DetachedCriteria 列表方法
- r - ggplot2:如何在带有长 Y 轴标签的绘图顶部水平居中图例?
- android - 我在将片段替换到另一个片段并查看视图时遇到问题,但我的问题是它与视图重叠,请帮助我?
- json - 谷歌 JSON 风格指南的替代品?
- azure - 表存储分区键可以更新吗?