c# get next item in list
MyList.SkipWhile(item => item.Name != "someName").Skip(1).FirstOrDefault()
c# get next item in list
MyList.SkipWhile(item => item.Name != "someName").Skip(1).FirstOrDefault()
C# list get next
List<string> strings = new List<string>() { "s1", "s2", "s3", "s4", "s5" };
// Use this if you're inside of a loop enumerating over the collection
//int index = strings.IndexOf(strings.GetEnumerator().Current);
// Use this if you're finding it manually
string currentString = "s3";
int index = strings.IndexOf(currentString);
string previousString = strings[index - 1];
string nextString = strings[index + 1];
Console.WriteLine("Previous: {0}\nCurrent: {1}\nNext: {2}", previousString, currentString, nextString);
Console.Read();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us