The ElementAt() method in C# to get elements at specified index position.
Firstly, set the string array.
string[] str = { "Jack", "Pat", "David"};Now, to get the element at a particular index, use the ElementAt() method as shown in the following example −
Example
using System.IO;
using System;
using System.Linq;
class Program {
static void Main() {
string[] str = { "Jack", "Pat", "David"};
Random r = new Random(DateTime.Now.Second);
// to generate random string
string res = str.AsQueryable().ElementAt(r.Next(0, str.Length));
Console.WriteLine("Random Name = '{0}'", res);
}
}Output
Random Name = 'Jack'