To find the maximum and minimum values in an array in C#, you can use a loop to iterate through the elements of the array and compare each element with the current maximum or minimum value. Here's an example:
main.cs305 chars19 lines
In this example, we initialize max
and min
to the first element of the array arr
. We then loop through the rest of the array and update max
and min
if we find a larger or smaller element.
At the end of the loop, max
and min
will contain the maximum and minimum values in the array, respectively. We can then print these values to the console.
gistlibby LogSnag