To find the range of a list of numbers in C#, you can use the System.Linq
namespace and the Max
and Min
methods of IEnumerable<T>
. Here's an example:
main.cs260 chars13 lines
Output:
main.cs28 chars2 lines
In this example, we first create an array of integers numbers
containing the list of numbers. We then use the Max
and Min
methods to find the maximum and minimum values in the array, respectively. The range is then calculated as the difference between the maximum and minimum values. Finally, we print the result to the console.
gistlibby LogSnag