Its a wonder what syntax errors creep in when you don't have a compiler handy. The below code has all been tested!
Here is the corrections and a sample project:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinqRandom;
namespace Program
{
class Program
{
static void Main(string[] args)
{
var x = new[] { 23, 303, -2332, 338, 8000, 100123, 254, 2234, 980, -90 };
Console.WriteLine("Count of Items:{0}", x.Count());
int count = 0;
foreach (var y in x.Radomized())
{
Console.WriteLine("Item #{0}:{1}", count++, y);
}
}
}
}
//End Sample project begin extension methods class
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace LinqRandom
{
public static class Class1
{
public static T NextRandom<T>(this IEnumerable<T> source)
{
Random gen = new Random((int)DateTime.Now.Ticks);
return source.Skip(gen.Next(0, source.Count() - 1) - 1).Take(1).ToArray()[0];
}
public static IEnumerable<T> Radomized<T>(this IEnumerable<T> source)
{
List<T> Remaining = new List<T>(source);
while (Remaining.Count >= 1)
{
T temp = NextRandom<T>(Remaining);
Remaining.Remove(temp);
yield return temp;
}
}
}
}