get item at index list c# code example
Example 1: c# list index
using System.Linq;
var myList = new List<string>{ "Yes", "No", "Maybe"};
var firstItem = myList.ElementAt(0);
Example 2: get last element of array c#
string[] str = new string[] {"Java","HTML","jQuery"};
Console.WriteLine("Last element: "+str[str.Length - 1])
Example 3: get string character by index c#
myString.[0];
myString.[0].ToString();
Example 4: c# list any retun indec
public class Item {
public int Id { get; set; }
public Item() {}
public Item(int id) { Id = id; }
}
List<Item> idList = { new Item(1), new Item(2), new Item(3) };
Item[] idLArr = [ new Item(1), new Item(2), new Item(3) ];
Item newItem = new Item(1);
int index = idList.FindIndex(item => item.Id == newItem.Id);
int arrIndex = Array.IndexOf(idLArr, newItem.Id);
if (index != -1)
{
}