CSharp examples for System.Collections:IEnumerable
Get Random value from IEnumerable
using System.Linq; using System.Collections.Generic; using System.Collections; using System;// w w w . java 2 s. c o m public class Main{ public static T GetRandom<T>(this IEnumerable<T> array) { //Determine the max length of our incoming array var maxLength = array.Count(); return array.ElementAt(R.Next(0, maxLength)); } }