06.HighQualityMethodsHomework/RefactorCSharpPart2Exam/11. CSharp-Part-2-Exam/CSharp-Part-2-Exam/DecreasingAbsoluteDifference/DecreasingAbsoluteDifference.cs
/// <summary>
/// Check if a list of 32-bit-integers is a decreasing sequence
/// and the absolute difference between neighbor elements is between 0 and 1
/// </summary>
/// <param name="numbers">List of 32-bit integers</param>
/// <returns>True or false</returns>
Check if a list of 32-bit-integers is a decreasing sequence
and the absolute difference between neighbor elements is between 0 and 1
Check if a list of 32 - bit - integers is a decreasing sequence and the absolute difference between neighbor elements is between 0 and 1
private static bool CheckSequence(List<int> numbers)
        {
            if(numbers.Count == 0)
            {
                throw new ArgumentException("List of numbers must contain at least one element");
            }
            int previousNumber, currentNumber;
            for (int i = 1; i < numbers.Count; i++)
            {
                previousNumber = numbers[i - 1];
                currentNumber = numbers[i];
                if (previousNumber >= currentNumber && Math.Abs(previousNumber - currentNumber) <= 1)
                {
                    continue;
                }
                else
                {
                    return false;
                }
            }
            return true;
        }
private static bool CheckSequence ( List < int > numbers ) { if ( numbers . Count == 0 ) { throw new ArgumentException ( " " ) ; } int previousNumber , currentNumber ; for ( int i = 1 ; i < numbers . Count ; i ++ ) { previousNumber = numbers [ i - 1 ] ; currentNumber = numbers [ i ] ; if ( previousNumber >= currentNumber && Math . Abs ( previousNumber - currentNumber ) <= 1 ) { continue ; } else { return false ; } } return true ; }
Check if a list of 32-bit-integers is a decreasing sequence
and the absolute difference between neighbor elements is between 0 and 1
Check if a list of 32 - bit - integers is a decreasing sequence and the absolute difference between neighbor elements is between 0 and 1
True or false
True or false
numbers
List<int>
List of 32-bit integers
List of 32 - bit integers