ElementAt() method in C#


ElementAt() is a System.Linq method in C# that is used to get and display element at a particular index.

The following is our string array −

string[] arr = { "One", "Two", "Three", "Four", "Five" };

Now to get an element at index 0, use the ElementAt() method −

arr.ElementAt(0);

The following is the complete code −

Example

 Live Demo

using System.IO;
using System;
using System.Linq;
public class Demo {
   public static void Main() {
      string[] arr = { "One", "Two", "Three", "Four", "Five" };
      // displaying element at index 0
      string res = arr.ElementAt(0);
      Console.WriteLine(res);
   }
}

Output

One

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 22-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements