True: 1 , -2 , -3 ,-4
True: -3,-15,-20,-30
False ( this has a positive number) -4,2,-5,-7,-9....
True: 1 , -2 , -3 ,-4
True: -3,-15,-20,-30
False ( this has a positive number) -4,2,-5,-7,-9....
According to your description, the following code might be useful:
public static bool IsTrue(int[] array)
{
bool re = true;
for (int i = 0; i < array.Length-1; i++)
{
if (array[i] < array[i + 1])
{
re = false;
break;
}
}
return re;
}
But the third example also seems to be True, which is decreasing.
Update:
public static bool IsTrue(List<int> array)
{
bool re = true;
for (int i = 0; i < array.Count-1; i++)
{
if (array[i] < array[i + 1])
{
re = false;
break;
}
}
return re;
}
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
8 people are following this question.