Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a list item by index

Tags:

c#

list

I've recently started using c# moving over from Java. I can't seem to find how to get a list item by index. In java to get the first item of the list it would be:

list1.get(0); 

What is the equivalent in c#?

like image 957
user1909486 Avatar asked Mar 17 '13 02:03

user1909486


People also ask

How do I get an index list?

The get() method of ArrayList in Java is used to get the element of a specified index within the list. Parameter: Index of the elements to be returned. It is of data-type int. Return Type: The element at the specified index in the given list.

Can you index a list in C#?

The IndexOf method returns the first index of an item if found in the List. C# List<T> class provides methods and properties to create a list of objects (classes). The IndexOf method returns the first index of an item if found in the List.

How do you get an item from a list Python?

To find an element in the list, use the Python list index() method, The index() is an inbuilt Python method that searches for an item in the list and returns its index. The index() method finds the given element in the list and returns its position.


1 Answers

list1[0]; 

Assuming list's type has an indexer defined.

like image 78
Mitch Wheat Avatar answered Oct 03 '22 01:10

Mitch Wheat