一天的游戏/报价 - 如何?[英] Game/Quote of the day - how to?

本文是小编为大家收集整理的关于一天的游戏/报价 - 如何?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有包含游戏的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];

给定列表至少有一个元素,显然.

本文地址:https://www.itbaoku.cn/post/1557138.html

问题描述

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.