My name is Edward Tanguay. I'm an American software and web developer living and working in Berlin, Germany.
C# CODE EXAMPLE created on Tuesday, September 07, 2010 permalink
Extension method to sort a generic collection of objects
This example shows a method which randomizes any generic collection you give it. It is based on the Fisher Yates shuffle.
using System.Collections.Generic;
using System;

namespace TestSort727272
{
    class Program
    {
        static void Main(string[] args)
        {
            List<MatchingItem> matchingItems = new List<MatchingItem>();

            matchingItems.Add(new MatchingItem("one", "111"));
            matchingItems.Add(new MatchingItem("two", "222"));
            matchingItems.Add(new MatchingItem("three", "333"));
            matchingItems.Add(new MatchingItem("four", "444"));

            MatchingItem.Display(matchingItems);
            matchingItems.Shuffle();
            MatchingItem.Display(matchingItems);
            matchingItems.Shuffle();
            MatchingItem.Display(matchingItems);

            Console.ReadLine();

        }
    }

    public class MatchingItem
    {
        public string LeftText { get; set; }
        public string RightText { get; set; }

        public MatchingItem(string leftText, string rightText)
        {
            LeftText = leftText;
            RightText = rightText;
        }

        public void Display()
        {
            Console.WriteLine(LeftText + " / " + RightText);
        }

        public static List<MatchingItem> ResortIntoRandomOrder(List<MatchingItem> matchingItems)
        {
            List<MatchingItem> newOrderItems = new List<MatchingItem>();
            //...matchingItems.Sort();
            return newOrderItems;
        }

        public static void Display(List<MatchingItem> matchingItems)
        {
            Console.WriteLine("");
            Console.WriteLine("--DISPLAY:-------------------------");
            foreach (var matchingItem in matchingItems)
            {
                matchingItem.Display();
            }
        }
    }

    public static class Helpers
    {
        static Random rng = new Random();
        public static void Shuffle<T>(this IList<T> list)
        {
            int n = list.Count;
            while (n > 1)
            {
                n--;
                int k = rng.Next(n + 1);
                T value = list[k];
                list[k] = list[n];
                list[n] = value;
            }
        }
    }
}
need markup?