Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
C# Linq ElementAt Method
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'
Advertisements
