Answered by:
max

-
Hi
I need to make a part of a code that founds the highest between more than two parameters, I know the command Math.max, but it only works for 2 parameters.
Can anyone give me a command for finding the highest (and lowest) between 3 or more parameters?
thank you
Question
Answers
-
Hi mashav manila,
According to the MSDN document of Math.Max Method, we could not add more than two parameters to Math.Max Method. If you want to get the max value between 3 numbers, I suggest you could use the following code:
Console.WriteLine(Math.Max(1, Math.Max(2, 3))); Console.ReadLine();
If you want to get the max values from a group of data (more than three), I think you should hand code it.
MSDN document about Math.Max Method:
https://msdn.microsoft.com/en-us/library/system.math.max%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
Sincerely,
Oscar
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
- Proposed as answer by qing__Moderator Tuesday, September 13, 2016 9:23 AM
- Edited by qing__Moderator Thursday, September 15, 2016 9:22 AM
- Marked as answer by qing__Moderator Tuesday, September 20, 2016 10:12 AM
All replies
-
Hi mashav manila,
According to the MSDN document of Math.Max Method, we could not add more than two parameters to Math.Max Method. If you want to get the max value between 3 numbers, I suggest you could use the following code:
Console.WriteLine(Math.Max(1, Math.Max(2, 3))); Console.ReadLine();
If you want to get the max values from a group of data (more than three), I think you should hand code it.
MSDN document about Math.Max Method:
https://msdn.microsoft.com/en-us/library/system.math.max%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396
Sincerely,
Oscar
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
- Proposed as answer by qing__Moderator Tuesday, September 13, 2016 9:23 AM
- Edited by qing__Moderator Thursday, September 15, 2016 9:22 AM
- Marked as answer by qing__Moderator Tuesday, September 20, 2016 10:12 AM
-
Hi mashav manila,
According to the above reply, please feel free to let us know your latest results, thank you very much.
Sincerely,
Oscar
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. Click HERE to participate the survey.
-
When you say parameters: how are the values stored?
There are Max/Min functions for List(of) for example that are really handy:
' Max in a List (doubles or other) ListOfDouble.Max ListOfDouble.Min
Now if you have a set of parameters that are not of the same class you can specify what you are looking for.
There are also possibilities to process the parameters inside the Max/Min as described in this msdn: https://msdn.microsoft.com/en-us/library/bb909383(v=vs.95).aspx
- Proposed as answer by qing__Moderator Monday, September 19, 2016 11:51 AM