יום שבת, 24 בינואר 2009

extension method


one line shuffling IEnumarable
actually two

public static IEnumerable Shuffle(this IEnumerable source)
{
Random rand=new Random(DateTime.Now.Ticks);

return source.Select(t => new Pair(rand.Next(), t)).OrderBy(pair => (int)pair.First)
.Select(pair => (T)pair.Second).ToList();

{


אין תגובות:

הוסף רשומת תגובה