0

我有一个数组。我想每次打电话时都以随机顺序写它的项目。我的数组是这样的。

string[] a= {"A","B","C","D","F"};
string[] a= new string[5];

例如顺序应该是这样的

C D F A B

但它应该改变顺序。

4

1 回答 1

1

你可以这样尝试:

string[] a = { "A", "B", "C", "D", "F" };
Random rand = new Random();
string[] RandArray = a.OrderBy(x => Guid.NewGuid()).ToArray();
string[] RandArray = a.OrderBy(x => rand.Next()).ToArray();
//any of these works.
于 2013-07-21T13:29:36.877 回答