使用LINQ和C#随机序列 [英] Random array using LINQ and C#

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

问题描述

我在读MSDN上杂志的一篇文章有​​关使用枚举类的LINQ 来生成随机排列。本文使用VB.NET,我没有立即确认相当于是在C#是什么:

 昏暗的RND作为新System.Random()
昏暗号码= Enumerable.Range(1,100)。 _
    排序依据(功能()rnd.Next)


解决方案

借助开发融合VB.Net到C#转换说,相当于C#code是:

  System.Random RND =新System.Random();
IEnumerable的< INT>号码= Enumerable.Range(1,100).OrderBy(R => rnd.Next());

有关备查,他们也有一个 C#到VB.Net转换。有提供这一点。

几个其他工具

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)

解决方案

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());

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天全站免登陆