none
max

    Question

  • 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

    Saturday, September 10, 2016 7:33 AM

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.


    Monday, September 12, 2016 4:51 AM
    Moderator

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.


    Monday, September 12, 2016 4:51 AM
    Moderator
  • 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.

    Monday, September 19, 2016 9:51 AM
    Moderator
  • 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
    Monday, September 19, 2016 10:13 AM