I have the following list of distinct strings:
"A"
"B"
"C"
If I want the item after A, I get B. After B, I get C. After C, I get A. Currently I have the following code, but for some reason it feels to me that there is a better way to go about this (maybe?).
private string GetNext(IList<string> items, string curr)
{
if (String.IsNullOrWhitespace(curr))
return items[0];
var index = items.IndexOf(curr);
if (index == -1)
return items[0];
return (index + 1 == items.Count) ? items[0] : items[index + 1];
}
I'm definitely open to a LINQ-esque way of doing this as well :)