Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [__DynamicallyInvokable]
- //The object, calling this method, is passed as an argument,
- // although this is not visible when we use code.
- public static int Max(this IEnumerable<int> source)
- {
- if (source != null)
- {
- int num = 0;
- bool flag = false;
- foreach (int num1 in source)
- {
- if (!flag)
- {
- num = num1;
- flag = true;
- }
- else
- {
- //Key moment
- //----------------
- if (num1 <= num) //Here, the tested value must be greater than current max value.
- {
- continue;
- }
- num = num1;
- //--------------------------
- }
- }
- if (!flag)
- {
- throw Error.NoElements();
- }
- else
- {
- return num;
- }
- }
- else
- {
- throw Error.ArgumentNull("source");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement