Answers for "get any random item in array c#"

C#
8

random value in array c#

Random random = new Random();
 int value = random.Next(0, array.Length);
 Console.Write(array[value]);
Posted by: Guest on July-05-2020
0

c# pick a random item from array

string[] names = new string[] { "name1", "name2", "name3" };
Random rnd = new Random();
int index = rnd.Next(names.Length);
Console.WriteLine($"Name: {names[index]}");
Posted by: Guest on October-28-2020
0

get any random item in array c#

Object[] obj = { "this", "that", "those" };
Random rn = new Random();
Object ob = rn.Next(0, obj.Length);
Posted by: Guest on April-29-2021

Code answers related to "get any random item in array c#"

C# Answers by Framework

Browse Popular Code Answers by Language