![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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