Skip to content

Instantly share code, notes, and snippets.

@FoxCouncil
Created November 14, 2019 08:43
Show Gist options
  • Save FoxCouncil/ad100e3fc7043f5830d5fbef9990432a to your computer and use it in GitHub Desktop.
Save FoxCouncil/ad100e3fc7043f5830d5fbef9990432a to your computer and use it in GitHub Desktop.
private static T GetNext<T>(IEnumerable<T> list, T current)
{
try
{
if (list.Last().Equals(current))
{
return list.First();
}
return list.SkipWhile(x => !x.Equals(current)).Skip(1).First();
}
catch
{
return default(T);
}
}
private static T GetPrevious<T>(IEnumerable<T> list, T current)
{
try
{
if (list.First().Equals(current))
{
return list.Last();
}
return list.TakeWhile(x => !x.Equals(current)).Last();
}
catch
{
return default(T);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment