问题描述
我有包含游戏的List<T>. 我想从该列表中选择1个游戏,这将是当天的游戏.
我不知道如何做到这一点.请贡献您的想法.
编辑: 随机将无法正常工作,因为每个页面加载游戏都会更改. 游戏选择没有具体的限制(投票,评级等). 至少这是我想到的.
如果可以在当前日期选择随机游戏,那就是完美的解决方案.
推荐答案
var gameOfTheDay = games[(uint)(DateTime.Today.GetHashCode()) % games.Length];
其他推荐答案
var random = new Random(); var index = random.Next(0, gameList.Count - 1); var gameOfTheDay = gameList[index];
其他推荐答案
使用 random.next方法索引:
var random = new Random(); int index = random.Next(list.Count); var game = list[index];
给定列表至少有一个元素,显然.
问题描述
i have List<T> that contains games. i want to select 1 game from that list that will be the game of the day.
i have no idea on how i can do that. Please, contribute your ideas.
EDIT: Random will not work, since every page load the game will change. There are no specific limits for the game selection ( votes,rating,whatever ). There should be a connection to the date due at least thats what i have in mind.
if a random game could be select by the current date, thats the perfect solution.
推荐答案
var gameOfTheDay = games[(uint)(DateTime.Today.GetHashCode()) % games.Length];
其他推荐答案
var random = new Random(); var index = random.Next(0, gameList.Count - 1); var gameOfTheDay = gameList[index];
其他推荐答案
Use Random.Next Method to get a random index:
var random = new Random(); int index = random.Next(list.Count); var game = list[index];
Given the list has at least one element, obviously.