目前工作的小控制台游戏,并想知道如果任何人有一个简单的方法来缩短这样的事情:简单的检查多条语句C#
if (map[playerX - 1, playerY] == "R1"
|| map[playerX - 1, playerY] == "R2"
|| map[playerX - 1, playerY] == "R3"
|| map[playerX - 1, playerY] == "Z1"
|| map[playerX - 1, playerY] == "Z2"
|| map[playerX - 1, playerY] == "Z3"
|| map[playerX - 1, playerY] == "S1 "
|| map[playerX - 1, playerY] == "S2"
|| map[playerX - 1, playerY] == "S3")
列了清单或东西,检查是否map[playerX-1, playerY]
等于其中的任何对象或东西。
感谢您的帮助提前。 Lukas Leder
我从来没有与前一个HashSet工作,并想知道如果你能告诉我如何创建一个。 –
hashSet继承collections.Generic。你可以初始化一个List <>,例如:HashSet set = new HashSet (); –
你说得对,HashSet是快速检查元素是否在集合中,但对于少数元素数组应该更快。 –