Public · Protected · Private
Randomize or shuffle a List
Type: Public  |  Created: 2012-06-25  |  Frozen: Yes
« Previous Public Blog Next Public Blog »
Comments
  • class myclass { public int MyValue{get;set;} public myclass(int input){MyValue = input;} } main() { List<myclass> a = new List<myclass>(); for (int i = 0; i < 10; i++){a.Add(new myclass(i));} string h = string.Empty; for (int i = 0; i < 10; i++) {h+=a[i].MyValue.ToString();} MessageBox.Show(h); Random rnd = new Random(); var nnn = a.OrderBy(b => rnd.Next()); //var nnn = a.OrderBy(b => Guid.NewGuid()); h = string.Empty; foreach (myclass m in nnn ){h += m.MyValue.ToString();} MessageBox.Show(h); }
    2012-06-25 19:23
This blog is frozen. No new comments or edits allowed.