提问人:Pesar 提问时间:5/28/2023 更新时间:5/29/2023 访问量:47
无法将类型“double”隐式转换为“long”。存在显式转换(是否缺少强制转换?
Cannot implicitly convert type 'double' to 'long'. An explicit conversion exists (are you missing a cast?)
问:
这是我的代码的第一部分,它声明并为其提供以下值:technology
1.0
static void Game1()
{
Random random = new Random();
Int64 startingCash = random.Next(4000, 5000);
Int64 startingVillagers = random.Next(4, 13);
double technology = 1.0;
Console.WriteLine("Your starting villagers are " + startingVillagers + ", and your starting cash is " + startingCash + ".");
Console.ReadLine();
MainGame(startingCash, startingVillagers, technology);
}
这是我代码的第二部分,发生错误的地方,这里是导致错误的地方。:tecnology += 0.5
else if (probability >= 7 && probability <= 10)
{
technology += 0.5;
Console.WriteLine("Your tech has increased, you now have " + technology + " Tech points.");
Console.ReadLine();
我试过使用 ,但还没有找到解决方案。long
Double
double
答:
0赞
AndrewBG
5/29/2023
#1
将 MainGame 方法的签名从中更改:
static void MainGame(Int64 startingCash, Int64 startingVillagers, long technology)
对此:
static void MainGame(Int64 startingCash, Int64 startingVillagers, double technology)
评论
MainGame
MainGame
technology