Get next index value in list c#
social.msdn.microsoft.com › Forums › en-USNov 13, 2014 · // Get your collection of values List<int> list = dtt.AsEnumerable().Select(r => r.Field<int>("Empno")).ToList(); // Find a particular element based on it's index int i = list.FindIndex(x => x == 1006); // Ensure the element at that index exists if(i != -1) { // It exists, so attempt to grab the next one (check the index of the next element) var next = list.ElementAtOrDefault(i + 1); // Ensure that element (the next element was found) if(next != null) { // The element exists and is stored in ...
C# get next item in list - programshelp.com
www.programshelp.com › help › csharpC# get next item in list MyList.SkipWhile(item => item.Name != "someName").Skip(1).FirstOrDefault() You can use indexer to get element at desired index. Adding one to index will get you next and subtracting one from index will give you previous element. int index = 4; int prev = list[index-1]; int next = list[index+1]; You can use indexer to get element at desired index.