Random Element from List - CSharp System.Collections.Generic

CSharp examples for System.Collections.Generic:List

Description

Random Element from List

Demo Code


using System.Collections.Generic;
using System;//from  ww  w.ja v a 2 s.  c o m

public class Main{
    public static T RandomElement<T>(this List<T> list)
      {
         var random = new Random();
         return list[random.Next(list.Count)];
      }
}

Related Tutorials