美好的一天我有一些关于从我的字符串数组中选择一个随机字符串的问题我目前正在开发一个猜字游戏。 这是我的字符串数组:从字符串数组中随机选择不重复
string[] movie = {"deadpool", "batmanvssuperman", "findingdory", "titanic", "suicidesquad", "lordoftherings", "harrypotter", "jurassicpark", "hungergames", "despicableme" };
,而这是在选择一个随机字符串,以我的数组的过程中,我应该做下一个,因为我要选择不重复的字符串。 例如 当程序启动时,它将选择一个字符串,然后当我再次选择随机字符串时,我想不选择先前已选择的单词。
string word = movie[r.Next(0, movie.Length)].ToUpper();
感谢您的回复!祝你今天愉快。
最经典的方法是创建一个洗牌阵列,而不是从原始数组随意挑选, – unwind