gpt4 book ai didi

c# - 为什么我的 for 循环告诉我我正在将 int 转换为 bool?

转载 作者:太空宇宙 更新时间:2023-11-03 18:59:11 24 4
gpt4 key购买 nike

这是我的代码...

for (int Position = 0; CardsInDeck.Length; Position++) 
{
if (RandomlySelectedCard == CardsInDeck [Position])
{
Position = 0;
} else {
CardsInDeck [Position] = RandomlySelectedCard;
}
}

Unity 告诉我它不能将 int 转换为 bool,但我已经检查了所有内容,看起来不错。顺便说一句,我正在制作纸牌游戏。

最佳答案

你的 for 循环说:

for (int Position = 0; CardsInDeck.Length; Position++) 

for 循环中的第二个参数应该是一个条件,因此它应该是:

for (int Position = 0; Position < CardsInDeck.Length; Position++)

关于c# - 为什么我的 for 循环告诉我我正在将 int 转换为 bool?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38810243/

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