Este artigo foi traduzido por máquina. Para visualizar o arquivo em inglês, marque a caixa de seleção Inglês. Você também pode exibir o texto Em inglês em uma janela pop-up, movendo o ponteiro do mouse sobre o texto.
Tradução
Inglês
Esta documentação foi arquivada e não está sendo atualizada.

Método Math.Max (UInt16, UInt16)

Retorna o maior dos dois inteiros não assinados de 16 bit.

Esta API não compatível com CLS. 

Namespace:  System
Assembly:  mscorlib (em mscorlib.dll)

[CLSCompliantAttribute(false)]
public static ushort Max(
	ushort val1,
	ushort val2
)

Parâmetros

val1
Tipo: System.UInt16
O primeiro dos dois inteiros não assinados de 16 bit para comparar.
val2
Tipo: System.UInt16
O segundo dos dois inteiros não assinados de 16 bit para comparar.

Valor de retorno

Tipo: System.UInt16
Parâmetro val1 ou val2, o que for maior.

O exemplo a seguir demonstra como usar o método Max para retornar e exibir mais de duas variáveis UInt16.

// This example demonstrates Math.Max()using System;

class Sample 
{
    publicstaticvoid 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 = 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("{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.
*/
// This example demonstrates Math.Max()
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        String str = "{0}: The greater of {1,3} and {2,3} is {3}.";
        String nl = Environment.get_NewLine();

        ubyte xByte1 = 1;
        ubyte xByte2 = 51;
        short xShort1 = -2;
        short xShort2 = 52;
        int xInt1 = -3;
        int xInt2 = 53;
        long xLong1 = -4;
        long xLong2 = 54;
        float xSingle1 = 5;
        float xSingle2 = 55;
        double xDouble1 = 6.0;
        double xDouble2 = 56.0;
        Decimal xDecimal1 = new Decimal(7);
        Decimal xDecimal2 = new Decimal(57);

        // The following types are not CLS-compliant.
        byte xSbyte1 = 101;
        byte xSbyte2 = 111;
        int xUshort1 = 102;

        //ToDo: Unsigned Integers not supported- converted to int
        int xUshort2 = 112;

        //ToDo: Unsigned Integers not supported- converted to int
        int xUint1 = 103;

        //ToDo: Unsigned Integers not supported- converted to int
        int xUint2 = 113;

        //ToDo: Unsigned Integers not supported- converted to int
        long xUlong1 = 104;

        //ToDo: Unsigned Integers not supported - converted to long
        long xUlong2 = 114;

        //ToDo: Unsigned Integers not supported - converted to long
        Console.WriteLine("{0}Display the greater of two values:{0}", nl);
        Console.WriteLine(str, 
            new Object[] { "Byte   ", (SByte)xByte1, (SByte)xByte2, 
            (SByte)System.Math.Max(xByte1, xByte2) });
        Console.WriteLine(str, 
            new Object[] { "Int16  ", (Int16)xShort1, (Int16)xShort2, 
            (Int16)System.Math.Max(xShort1, xShort2) });
        Console.WriteLine(str, 
            new Object[] { "Int32  ", (Int32)xInt1, (Int32)xInt2, 
                (Int32)System.Math.Max(xInt1, xInt2) });
        Console.WriteLine(str, 
            new Object[] { "Int64  ", (Int64)xLong1, (Int64)xLong2, 
                (Int64)System.Math.Max(xLong1, xLong2) });
        Console.WriteLine(str, 
            new Object[] { "Single ", (System.Single)xSingle1, 
            (System.Single)xSingle2, 
            (System.Single)System.Math.Max(xSingle1, xSingle2) });
        Console.WriteLine(str, 
            new Object[] { "Double ", (System.Double)xDouble1, 
            (System.Double)xDouble2, 
            (System.Double)System.Math.Max(xDouble1, xDouble2) });
        Console.WriteLine(str, 
            new Object[] { "Decimal", 
            (System.Decimal)xDecimal1, (System.Decimal)xDecimal2, 
            (System.Decimal)System.Math.Max(xDecimal1, xDecimal2) });
        //
        Console.WriteLine("{0}The following types are not CLS-compliant.{0}",nl);
        Console.WriteLine(str, 
            new Object[] { "SByte  ", (System.Byte)xSbyte1, (System.Byte)xSbyte2, 
            (System.Byte)System.Math.Max(xSbyte1, xSbyte2) });
        Console.WriteLine(str, 
            new Object[] { "UInt16 ", (UInt16)xUshort1, (UInt16)xUshort2, 
            (UInt16)System.Math.Max(xUshort1, xUshort2) });
        Console.WriteLine(str, 
            new Object[] { "UInt32 ", (UInt32)xUint1, (UInt32)xUint2, 
            (UInt32)System.Math.Max(xUint1, xUint2) });
        Console.WriteLine(str, 
            new Object[] { "UInt64 ", (UInt64)xUlong1, (UInt64)xUlong2, 
                (UInt64)System.Math.Max(xUlong1, xUlong2) });
    } //main
} //Sample

/*
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.
*/


Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360

o.NET Framework e.NET Compact Framework não oferecem suporte a todas as versões de cada plataforma. Para obter uma lista de versões suportadas, consulte Requisitos de sistema do .NET framework.

.NET Framework

Compatível com: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatível com: 3.5, 2.0, 1.0

XNA Framework

Compatível com: , 1.0
Mostrar: