What is the purpose of ElementAt?

 Posted by Niladri.Biswas on 6/9/2013 | Category: LINQ Interview questions | Views: 3522 | Points: 40
Answer:

The ElementAt operator retrieves the element at a given index in the collection.
e.g.

string[] names =

{ "Niladri", "Arina", "Bob","Foo", "Bar" };
Random random = new Random(DateTime.Now.Millisecond);

string name = names.ElementAt(3);

Console.WriteLine("The name chosen is '{0}'.", name);




/*
This code produces the following sample output:

The name chosen at random is 'Foo'.
*/


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response