Says I have this List : 1, 3, 5, 7, 9, 13
For example, given value is : 9, the previous item is 7 and the next item is 13
How can I achieve this using C#?
List listInts = new List(); listInts.AddRange(new int[] { 1, 3, 5, 7, 9, 13 }); int index = listInts.IndexOf(3); //The index here would be "1" index++; //Check first if the index is in the length int element = listInts[index]; //element = 5