gpt4 book ai didi

c# - 无法将类型 'string' 隐式转换为 'bool'

转载 作者:太空狗 更新时间:2023-10-29 17:32:12 28 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
Help converting type - cannot implicitly convert type 'string' to 'bool'

我有这个代码:

private double Price;
private bool Food;
private int count;
private decimal finalprice;

public void Readinput()
{
Console.Write("Unit price: ");
Price = Console.ReadLine();

Console.Write("Food item y/n: ");
Food = Console.ReadLine();

Console.Write("Count: ");
count = Console.ReadLine();
}

private void calculateValues()
{
finalprice = Price * count;
}

并得到以下错误:

Cannot implicitly convert type 'string' to 'bool'

Cannot implicitly convert type 'string' to 'double'

Cannot implicitly convert type 'string' to 'int'

Cannot implicitly convert type 'double' to 'decimal'. An explicit conversion exists (are you missing a cast?)

我知道这意味着什么,但我不知道如何修复它。

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