Randomise a List

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

Leave a Comment

Your email address will not be published. Required fields are marked *

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