This is one of the reasons why I love LINQ, its so easy to do something like randomise a list in just one line that used to take a few lines.

The only thing you need to remember with this code is that you need to have specified that you’re using System.Linq in order for it to work.

List myCollection = new List();

myCollection = myCollection.OrderBy(a => Guid.NewGuid()).ToList()
Randomise a List
Tagged on:     

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.