gpt4 book ai didi

c# - 数组问题(无法将类型 'int' 隐式转换为 'int[]')

转载 作者:行者123 更新时间:2023-11-30 22:57:49 25 4
gpt4 key购买 nike

我整晚都在寻找一个存储系统的修复程序,用于从一个循环到 3 个循环的限制的用户输入。我相信我已经找到了它,但是正如标题所说,我在用户输入的 console.readline 上收到错误 Cannot implicitly Convert Type 'int' to 'int[]'?关于如何解决这个问题的任何建议?

提前谢谢你。

            //Array For Ticket prices, sales and user input
int[] TicketChoices = new int[3];

//Ticket Types
//ChildT = £1.50 = Child;
//AdultT = £2.35 = Adult;
//StudentT = £1.99 = Student;

//Film Certificate Seats Screen
//Jaws 12A 15 1
//The Exorcist 18 33 2

cw("Hello Current tickets are:");

for (int I = 0; I < 3; I++)

{
cw("ID (1) Child, £1.50");
cw("ID:(2) Adult, £2,35");
cw("ID:(3) Student £1.99");
cw("");
cw("Please Select Which ticket you would like to input By Entering it's id Number");
cw("input Must be between 1-3 for it to be vaild.");
TicketChoices = int.Parse(Console.ReadLine());

}

最佳答案

这是我认为您正在尝试做的:

    static void Main()
{
//Array For Ticket prices, sales and user input
var ticketChoices = new int[3];

//Ticket Types
//ChildT = £1.50 = Child;
//AdultT = £2.35 = Adult;
//StudentT = £1.99 = Student;

//Film Certificate Seats Screen
//Jaws 12A 15 1
//The Exorcist 18 33 2

Console.WriteLine("Hello Current tickets are:");

for (var i = 0; i < 3; i++)

{
Console.WriteLine("ID (1) Child, £1.50");
Console.WriteLine("ID:(2) Adult, £2,35");
Console.WriteLine("ID:(3) Student £1.99");
Console.WriteLine("");
Console.WriteLine("Please Select Which ticket you would like to input By Entering it's id Number");
Console.WriteLine("input Must be between 1-3 for it to be vaild.");
var valid = false;
while (!valid)
{
var input = Console.ReadLine();
if (int.TryParse(input, out var ticketNumber))
{
if (ticketNumber >= 0 && ticketNumber <= 3)
{
valid = true;
}
}

if (valid)
{
ticketChoices[i] = ticketNumber;
}
else
{
Console.WriteLine("Please enter a value between 1 and 3");
}
}
}

// Print the results
Console.WriteLine("You entered:");
foreach (var ticketChoice in ticketChoices)
{
Console.WriteLine(ticketChoice);
}

Console.ReadLine();
}

关于c# - 数组问题(无法将类型 'int' 隐式转换为 'int[]'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53384341/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com