使用 LINQ 和 C# 的随机数组 [英] Random array using LINQ and C#

查看:31
本文介绍了使用 LINQ 和 C# 的随机数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 MSDN 杂志上阅读了一篇关于在 LINQ 中使用 可枚举类的文章 生成随机数组.这篇文章使用了 VB.NET,我不能立即确定 C# 中的等价物是什么:

I was reading an article on MSDN Magazine about using the Enumerable class in LINQ to generate a random array. The article uses VB.NET and I'm not immediately sure what the equivalent is in C#:

Dim rnd As New System.Random()
Dim numbers = Enumerable.Range(1, 100). _
    OrderBy(Function() rnd.Next)

推荐答案

开发人员 Fusion VB.Net to C# 转换器说等效的 C# 代码是:

The Developer Fusion VB.Net to C# converter says that the equivalent C# code is:

System.Random rnd = new System.Random();
IEnumerable<int> numbers = Enumerable.Range(1, 100).OrderBy(r => rnd.Next());

为了将来参考,他们还有一个C# 到 VB.Net 转换器.还有一些其他工具可用于此目的.

For future reference, they also have a C# to VB.Net converter. There are several other tools available for this as well.

这篇关于使用 LINQ 和 C# 的随机数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆