Math.Max Metoda

Definicja

Zwraca większe z dwóch podanych liczb.Returns the larger of two specified numbers.

Przeciążenia

Max(UInt16, UInt16)

Zwraca większą z 2 16-bitowych liczb całkowitych bez znaku.Returns the larger of two 16-bit unsigned integers.

Max(Single, Single)

Zwraca więcej dwóch liczb zmiennoprzecinkowych o pojedynczej precyzji.Returns the larger of two single-precision floating-point numbers.

Max(UInt64, UInt64)

Zwraca większą z 2 64-bitowych liczb całkowitych bez znaku.Returns the larger of two 64-bit unsigned integers.

Max(UInt32, UInt32)

Zwraca większą z 2 32-bitowych liczb całkowitych bez znaku.Returns the larger of two 32-bit unsigned integers.

Max(SByte, SByte)

Zwraca większą z 2 8-bitowych liczb całkowitych ze znakiem.Returns the larger of two 8-bit signed integers.

Max(Byte, Byte)

Zwraca większą z 2 8-bitowych liczb całkowitych bez znaku.Returns the larger of two 8-bit unsigned integers.

Max(Int32, Int32)

Zwraca większą z 2 32-bitowych liczb całkowitych ze znakiem.Returns the larger of two 32-bit signed integers.

Max(Int16, Int16)

Zwraca większą z 2 16-bitowych liczb całkowitych ze znakiem.Returns the larger of two 16-bit signed integers.

Max(Double, Double)

Zwraca więcej dwóch liczb zmiennoprzecinkowych o podwójnej precyzji.Returns the larger of two double-precision floating-point numbers.

Max(Decimal, Decimal)

Zwraca większą z dwóch liczb dziesiętnych.Returns the larger of two decimal numbers.

Max(Int64, Int64)

Zwraca większą z 2 64-bitowych liczb całkowitych ze znakiem.Returns the larger of two 64-bit signed integers.

Przykłady

Poniższy przykład ilustruje sposób użycia Max metody w celu zwrócenia i wyświetlenia większej liczby dwóch zmiennych:The following example demonstrates how to use the Max method to return and display the greater of two variables:

// This example demonstrates Math.Max()
using namespace System;
int main()
{
   String^ str = "{0}: The greater of {1,3} and {2,3} is {3}.";
   String^ nl = Environment::NewLine;
   Byte xByte1 = 1,xByte2 = 51;
   short xShort1 = -2,xShort2 = 52;
   int xInt1 = -3,xInt2 = 53;
   long xLong1 = -4,xLong2 = 54;
   float xSingle1 = 5.0f,xSingle2 = 55.0f;
   double xDouble1 = 6.0,xDouble2 = 56.0;
   Decimal xDecimal1 = 7,xDecimal2 = 57;
   
   // The following types are not CLS-compliant.
   SByte xSbyte1 = 101,xSbyte2 = 111;
   UInt16 xUshort1 = 102,xUshort2 = 112;
   UInt32 xUint1 = 103,xUint2 = 113;
   UInt64 xUlong1 = 104,xUlong2 = 114;
   Console::WriteLine( "{0}Display the greater of two values:{0}", nl );
   Console::WriteLine( str, "Byte   ", xByte1, xByte2, Math::Max( xByte1, xByte2 ) );
   Console::WriteLine( str, "Int16  ", xShort1, xShort2, Math::Max( xShort1, xShort2 ) );
   Console::WriteLine( str, "Int32  ", xInt1, xInt2, Math::Max( xInt1, xInt2 ) );
   Console::WriteLine( str, "Int64  ", xLong1, xLong2, Math::Max( xLong1, xLong2 ) );
   Console::WriteLine( str, "Single ", xSingle1, xSingle2, Math::Max( xSingle1, xSingle2 ) );
   Console::WriteLine( str, "Double ", xDouble1, xDouble2, Math::Max( xDouble1, xDouble2 ) );
   Console::WriteLine( str, "Decimal", xDecimal1, xDecimal2, Math::Max( xDecimal1, xDecimal2 ) );
   
   //
   Console::WriteLine( "{0}The following types are not CLS-compliant.{0}", nl );
   Console::WriteLine( str, "SByte  ", xSbyte1, xSbyte2, Math::Max( xSbyte1, xSbyte2 ) );
   Console::WriteLine( str, "UInt16 ", xUshort1, xUshort2, Math::Max( xUshort1, xUshort2 ) );
   Console::WriteLine( str, "UInt32 ", xUint1, xUint2, Math::Max( xUint1, xUint2 ) );
   Console::WriteLine( str, "UInt64 ", xUlong1, xUlong2, Math::Max( xUlong1, xUlong2 ) );
}

/*
This example produces the following results:

Display the greater of two values:

Byte   : The greater of   1 and  51 is 51.
Int16  : The greater of  -2 and  52 is 52.
Int32  : The greater of  -3 and  53 is 53.
Int64  : The greater of  -4 and  54 is 54.
Single : The greater of   5 and  55 is 55.
Double : The greater of   6 and  56 is 56.
Decimal: The greater of   7 and  57 is 57.

(The following types are not CLS-compliant.)

SByte  : The greater of 101 and 111 is 111.
UInt16 : The greater of 102 and 112 is 112.
UInt32 : The greater of 103 and 113 is 113.
UInt64 : The greater of 104 and 114 is 114.
*/
string str = "{0}: The greater of {1,3} and {2,3} is {3}.";

byte     xByte1    = 1,    xByte2    = 51;	
short    xShort1   = -2,   xShort2   = 52;
int      xInt1     = -3,   xInt2     = 53;
long     xLong1    = -4,   xLong2    = 54;
float    xSingle1  = 5.0f, xSingle2  = 55.0f;
double   xDouble1  = 6.0,  xDouble2  = 56.0;
Decimal  xDecimal1 = 7m,   xDecimal2 = 57m;

// The following types are not CLS-compliant.
sbyte    xSbyte1   = 101, xSbyte2  = 111;
ushort   xUshort1  = 102, xUshort2 = 112;
uint     xUint1    = 103, xUint2   = 113;
ulong    xUlong1   = 104, xUlong2  = 114;

Console.WriteLine("Display the greater of two values:\n");
Console.WriteLine(str, "Byte   ", xByte1, xByte2, Math.Max(xByte1, xByte2));
Console.WriteLine(str, "Int16  ", xShort1, xShort2, Math.Max(xShort1, xShort2));
Console.WriteLine(str, "Int32  ", xInt1, xInt2, Math.Max(xInt1, xInt2));
Console.WriteLine(str, "Int64  ", xLong1, xLong2, Math.Max(xLong1, xLong2));
Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Max(xSingle1, xSingle2));
Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Max(xDouble1, xDouble2));
Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Max(xDecimal1, xDecimal2));

Console.WriteLine("\nThe following types are not CLS-compliant.\n");
Console.WriteLine(str, "SByte  ", xSbyte1, xSbyte2, Math.Max(xSbyte1, xSbyte2));
Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Max(xUshort1, xUshort2));
Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Max(xUint1, xUint2));
Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Max(xUlong1, xUlong2));

/*
This example produces the following results:

Display the greater of two values:

Byte   : The greater of   1 and  51 is 51.
Int16  : The greater of  -2 and  52 is 52.
Int32  : The greater of  -3 and  53 is 53.
Int64  : The greater of  -4 and  54 is 54.
Single : The greater of   5 and  55 is 55.
Double : The greater of   6 and  56 is 56.
Decimal: The greater of   7 and  57 is 57.

(The following types are not CLS-compliant.)

SByte  : The greater of 101 and 111 is 111.
UInt16 : The greater of 102 and 112 is 112.
UInt32 : The greater of 103 and 113 is 113.
UInt64 : The greater of 104 and 114 is 114.
*/
' This example demonstrates Math.Max()
Class Sample
   Public Shared Sub Main()
      Dim str As String = "{0}: The greater of {1,3} and {2,3} is {3}."
      Dim nl As String = Environment.NewLine
      
      Dim xByte1 As Byte = 1
      Dim xByte2 As Byte = 51
      Dim xShort1 As Short = - 2
      Dim xShort2 As Short = 52
      Dim xInt1 As Integer = - 3
      Dim xInt2 As Integer = 53
      Dim xLong1 As Long = - 4
      Dim xLong2 As Long = 54
      Dim xSingle1 As Single = 5F
      Dim xSingle2 As Single = 55F
      Dim xDouble1 As Double = 6.0
      Dim xDouble2 As Double = 56.0
      Dim xDecimal1 As [Decimal] = 7D
      Dim xDecimal2 As [Decimal] = 57D
      
      ' The following types are not CLS-compliant.
      Dim xSByte1 As SByte = 101
      Dim xSByte2 As SByte = 111
      Dim xUShort1 As UShort = 102
      Dim xUShort2 As UShort = 112
      Dim xUint1 As UInteger = 103
      Dim xUint2 As UInteger = 113
      Dim xUlong1 As ULong = 104
      Dim xUlong2 As ULong = 114
      
      Console.WriteLine("{0}Display the greater of two values:{0}", nl)
      Console.WriteLine(str, "Byte   ", xByte1, xByte2, Math.Max(xByte1, xByte2))
      Console.WriteLine(str, "Int16  ", xShort1, xShort2, Math.Max(xShort1, xShort2))
      Console.WriteLine(str, "Int32  ", xInt1, xInt2, Math.Max(xInt1, xInt2))
      Console.WriteLine(str, "Int64  ", xLong1, xLong2, Math.Max(xLong1, xLong2))
      Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Max(xSingle1, xSingle2))
      Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Max(xDouble1, xDouble2))
      Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Max(xDecimal1, xDecimal2))
      '
      Console.WriteLine("{0}(The following types are not CLS-compliant.){0}", nl)
      Console.WriteLine(str, "SByte  ", xSByte1, xSByte2, Math.Max(xSByte1, xSByte2))
      Console.WriteLine(str, "UInt16 ", xUShort1, xUShort2, Math.Max(xUShort1, xUShort2))
      Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Max(xUint1, xUint2))
      Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Max(xUlong1, xUlong2))
   End Sub
End Class
'
'This example produces the following results:
'
'Display the greater of two values:
'
'Byte   : The greater of   1 and  51 is 51.
'Int16  : The greater of  -2 and  52 is 52.
'Int32  : The greater of  -3 and  53 is 53.
'Int64  : The greater of  -4 and  54 is 54.
'Single : The greater of   5 and  55 is 55.
'Double : The greater of   6 and  56 is 56.
'Decimal: The greater of   7 and  57 is 57.
'
' (The following types are not CLS-compliant.)
' 
' SByte  : The greater of 101 and 111 is 111.
' UInt16 : The greater of 102 and 112 is 112.
' UInt32 : The greater of 103 and 113 is 113.
' UInt64 : The greater of 104 and 114 is 114.

Max(UInt16, UInt16)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Zwraca większą z 2 16-bitowych liczb całkowitych bez znaku.Returns the larger of two 16-bit unsigned integers.

public:
 static System::UInt16 Max(System::UInt16 val1, System::UInt16 val2);
public static ushort Max (ushort val1, ushort val2);
[System.CLSCompliant(false)]
public static ushort Max (ushort val1, ushort val2);
static member Max : uint16 * uint16 -> uint16
[<System.CLSCompliant(false)>]
static member Max : uint16 * uint16 -> uint16
Public Shared Function Max (val1 As UShort, val2 As UShort) As UShort

Parametry

val1
UInt16

Pierwszy z 2 16-bitowych liczb całkowitych bez znaku do porównania.The first of two 16-bit unsigned integers to compare.

val2
UInt16

Druga z 2 16-bitowych liczb całkowitych bez znaku do porównania.The second of two 16-bit unsigned integers to compare.

Zwraca

UInt16

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Atrybuty

Dotyczy

Max(Single, Single)

Zwraca więcej dwóch liczb zmiennoprzecinkowych o pojedynczej precyzji.Returns the larger of two single-precision floating-point numbers.

public:
 static float Max(float val1, float val2);
public static float Max (float val1, float val2);
static member Max : single * single -> single
Public Shared Function Max (val1 As Single, val2 As Single) As Single

Parametry

val1
Single

Pierwszy z dwóch liczb zmiennoprzecinkowych o pojedynczej precyzji do porównania.The first of two single-precision floating-point numbers to compare.

val2
Single

Druga z dwóch liczb zmiennoprzecinkowych o pojedynczej precyzji do porównania.The second of two single-precision floating-point numbers to compare.

Zwraca

Single

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger. Opcja if val1 , or val2 lub or val1 val2 jest równa NaN , NaN jest zwracana.If val1, or val2, or both val1 and val2 are equal to NaN, NaN is returned.

Dotyczy

Max(UInt64, UInt64)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Zwraca większą z 2 64-bitowych liczb całkowitych bez znaku.Returns the larger of two 64-bit unsigned integers.

public:
 static System::UInt64 Max(System::UInt64 val1, System::UInt64 val2);
public static ulong Max (ulong val1, ulong val2);
[System.CLSCompliant(false)]
public static ulong Max (ulong val1, ulong val2);
static member Max : uint64 * uint64 -> uint64
[<System.CLSCompliant(false)>]
static member Max : uint64 * uint64 -> uint64
Public Shared Function Max (val1 As ULong, val2 As ULong) As ULong

Parametry

val1
UInt64

Pierwszy z 2 64-bitowych liczb całkowitych bez znaku do porównania.The first of two 64-bit unsigned integers to compare.

val2
UInt64

Druga z 2 64-bitowych liczb całkowitych bez znaku do porównania.The second of two 64-bit unsigned integers to compare.

Zwraca

UInt64

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Atrybuty

Dotyczy

Max(UInt32, UInt32)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Zwraca większą z 2 32-bitowych liczb całkowitych bez znaku.Returns the larger of two 32-bit unsigned integers.

public:
 static System::UInt32 Max(System::UInt32 val1, System::UInt32 val2);
public static uint Max (uint val1, uint val2);
[System.CLSCompliant(false)]
public static uint Max (uint val1, uint val2);
static member Max : uint32 * uint32 -> uint32
[<System.CLSCompliant(false)>]
static member Max : uint32 * uint32 -> uint32
Public Shared Function Max (val1 As UInteger, val2 As UInteger) As UInteger

Parametry

val1
UInt32

Pierwszy z 2 32-bitowych liczb całkowitych bez znaku do porównania.The first of two 32-bit unsigned integers to compare.

val2
UInt32

Druga z 2 32-bitowych liczb całkowitych bez znaku do porównania.The second of two 32-bit unsigned integers to compare.

Zwraca

UInt32

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Atrybuty

Dotyczy

Max(SByte, SByte)

Ważne

Ten interfejs API nie jest zgodny ze specyfikacją CLS.

Zwraca większą z 2 8-bitowych liczb całkowitych ze znakiem.Returns the larger of two 8-bit signed integers.

public:
 static System::SByte Max(System::SByte val1, System::SByte val2);
public static sbyte Max (sbyte val1, sbyte val2);
[System.CLSCompliant(false)]
public static sbyte Max (sbyte val1, sbyte val2);
static member Max : sbyte * sbyte -> sbyte
[<System.CLSCompliant(false)>]
static member Max : sbyte * sbyte -> sbyte
Public Shared Function Max (val1 As SByte, val2 As SByte) As SByte

Parametry

val1
SByte

Pierwsze z 2 8-bitowych liczb całkowitych ze znakiem do porównania.The first of two 8-bit signed integers to compare.

val2
SByte

Druga z 2 8-bitowych liczb całkowitych ze znakiem do porównania.The second of two 8-bit signed integers to compare.

Zwraca

SByte

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Atrybuty

Dotyczy

Max(Byte, Byte)

Zwraca większą z 2 8-bitowych liczb całkowitych bez znaku.Returns the larger of two 8-bit unsigned integers.

public:
 static System::Byte Max(System::Byte val1, System::Byte val2);
public static byte Max (byte val1, byte val2);
static member Max : byte * byte -> byte
Public Shared Function Max (val1 As Byte, val2 As Byte) As Byte

Parametry

val1
Byte

Pierwszy z 2 8-bitowych liczb całkowitych bez znaku do porównania.The first of two 8-bit unsigned integers to compare.

val2
Byte

Druga z 2 8-bitowych liczb całkowitych bez znaku do porównania.The second of two 8-bit unsigned integers to compare.

Zwraca

Byte

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Dotyczy

Max(Int32, Int32)

Zwraca większą z 2 32-bitowych liczb całkowitych ze znakiem.Returns the larger of two 32-bit signed integers.

public:
 static int Max(int val1, int val2);
public static int Max (int val1, int val2);
static member Max : int * int -> int
Public Shared Function Max (val1 As Integer, val2 As Integer) As Integer

Parametry

val1
Int32

Pierwsze z 2 32-bitowych liczb całkowitych ze znakiem do porównania.The first of two 32-bit signed integers to compare.

val2
Int32

Druga z 2 32-bitowych liczb całkowitych ze znakiem do porównania.The second of two 32-bit signed integers to compare.

Zwraca

Int32

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Dotyczy

Max(Int16, Int16)

Zwraca większą z 2 16-bitowych liczb całkowitych ze znakiem.Returns the larger of two 16-bit signed integers.

public:
 static short Max(short val1, short val2);
public static short Max (short val1, short val2);
static member Max : int16 * int16 -> int16
Public Shared Function Max (val1 As Short, val2 As Short) As Short

Parametry

val1
Int16

Pierwsze z 2 16-bitowych liczb całkowitych ze znakiem do porównania.The first of two 16-bit signed integers to compare.

val2
Int16

Druga z 2 16-bitowych liczb całkowitych ze znakiem do porównania.The second of two 16-bit signed integers to compare.

Zwraca

Int16

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Dotyczy

Max(Double, Double)

Zwraca więcej dwóch liczb zmiennoprzecinkowych o podwójnej precyzji.Returns the larger of two double-precision floating-point numbers.

public:
 static double Max(double val1, double val2);
public static double Max (double val1, double val2);
static member Max : double * double -> double
Public Shared Function Max (val1 As Double, val2 As Double) As Double

Parametry

val1
Double

Pierwsze dwie liczby zmiennoprzecinkowe podwójnej precyzji do porównania.The first of two double-precision floating-point numbers to compare.

val2
Double

Druga z dwóch liczb zmiennoprzecinkowych o podwójnej precyzji do porównania.The second of two double-precision floating-point numbers to compare.

Zwraca

Double

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger. Jeśli val1 , val2 , lub obie val1 i val2 są równe NaN , NaN jest zwracana wartość.If val1, val2, or both val1 and val2 are equal to NaN, NaN is returned.

Dotyczy

Max(Decimal, Decimal)

Zwraca większą z dwóch liczb dziesiętnych.Returns the larger of two decimal numbers.

public:
 static System::Decimal Max(System::Decimal val1, System::Decimal val2);
public static decimal Max (decimal val1, decimal val2);
static member Max : decimal * decimal -> decimal
Public Shared Function Max (val1 As Decimal, val2 As Decimal) As Decimal

Parametry

val1
Decimal

Pierwsze dwie liczby dziesiętne do porównania.The first of two decimal numbers to compare.

val2
Decimal

Druga z dwóch liczb dziesiętnych do porównania.The second of two decimal numbers to compare.

Zwraca

Decimal

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Dotyczy

Max(Int64, Int64)

Zwraca większą z 2 64-bitowych liczb całkowitych ze znakiem.Returns the larger of two 64-bit signed integers.

public:
 static long Max(long val1, long val2);
public static long Max (long val1, long val2);
static member Max : int64 * int64 -> int64
Public Shared Function Max (val1 As Long, val2 As Long) As Long

Parametry

val1
Int64

Pierwsze z 2 64-bitowych liczb całkowitych ze znakiem do porównania.The first of two 64-bit signed integers to compare.

val2
Int64

Druga z 2 64-bitowych liczb całkowitych ze znakiem do porównania.The second of two 64-bit signed integers to compare.

Zwraca

Int64

Parametr val1 lub val2 , w zależności od tego, jest większy.Parameter val1 or val2, whichever is larger.

Dotyczy