C# Windows Phone 7 中的随机字符串列表
我到处都在寻找如何在 Windows Phone 7 上用 C# 随机排列/随机化字符串列表。我仍然是一个初学者,你可以说这可能超出了我的范围,但我正在编写一个简单的应用程序,这就是它的基础。我有一个字符串列表,需要将其打乱并输出到文本块。我查过一些代码,但我知道我错了。有什么建议吗?
I've looked everywhere on how to shuffle/randomize a string list in C# for the windows phone 7. I'm still a beginner you could say so this is probably way out of my league, but I'm writing a simple app, and this is the base of it. I have a list of strings that I need to shuffle and output to a text block. I have bits and pieces of codes I've looked up, but I know I have it wrong. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Fisher-Yates-Durstenfeld shuffle 是一项经过验证的技术,易于实施。下面是一个扩展方法,它将对任何
IList
执行就地随机播放。(如果您决定完整保留原始列表并返回一个新的、经过重新排序的列表,或者到 作用于
IEnumerable
序列,à la LINQ。)The Fisher-Yates-Durstenfeld shuffle is a proven technique that's easy to implement. Here's an extension method that will perform an in-place shuffle on any
IList<T>
.(It should be easy enough to adapt if you decide that you want to leave the original list intact and return a new, shuffled list instead, or to act on
IEnumerable<T>
sequences, à la LINQ.)