Created
November 14, 2019 08:43
-
-
Save FoxCouncil/ad100e3fc7043f5830d5fbef9990432a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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