c# - 检查列表是否有重复项
问题描述
我正在尝试进行检查并运行一个方法,直到它为真。
public struct Letter
{
public string letter;
}
private void DoStart()
{
UsedIndexes.Clear();
BuildGoodGame();
}
List<Letter> usedLetter = new List<Letter>();
private void BuildGoodGame()
{
usedLetter.Clear();
Letter temp;
for (int i = 0; i < Couch.Length; i++)
{
do
{
couchIndex = CouchNameRandom.getRandom();
Couch[i].setCurrentChildIndex(couchIndex);
MisingLetterScript thisLetter = Couch[i].CurrentChild.GetComponent<MisingLetterScript>();
string s = thisLetter.Letter;
temp = new Letter
{
letter = s
};
} while (UsedNames.Contains(couchIndex) || usedLetter.Contains(temp));
UsedNames.Add(couchIndex);
usedLetter.Add(temp);
}
}
我想运行这段代码两次,第一次运行正常,它完全完美。第二次,我执行 Invoke("DoStart", 1f) 并且它不再运行,通常冻结 Unity。整个问题在于 returnable 方法,它检查列表是否包含重复项。我不明白为什么第一次工作正常,然后我再次调用 DoStart 方法后,它就冻结了。帮助!!谢谢你。
解决方案
推荐阅读
- android - Android PDF 到 Base64 的转换不起作用
- mongoose - AdonisJS RuntimeException:E_CANNOT_LOGIN:无法登录用户,因为未定义用户 ID
- flutter - 如何在颤振中使用地图来解决我遇到的问题
- xcode - Xcode:将随机显示的条目/文本从数据库保存到文件
- python - 如何正确键入提示键是 Type[T] 且值是该类型的泛型的 Python dict?
- ubuntu - 系统调用可以有局部变量并记住它们的值吗?
- mysql - 使用 sql 删除记录,如果它大于某个数字并附加一个单位(例如 3M 或 3cm)
- php - 如何在“woocommerce_after_order_notes”中设置类属性,然后在“woocommerce_checkout_process”中使用它?
- mysql - 为什么 --default-character-set=utf8mb4 对客户端连接没有影响?
- java - 未找到 404 进行更新