Export (0) Print
Expand All
0 out of 4 rated this helpful - Rate this topic

Math.Min Method (UInt32, UInt32)

Returns the smaller of two 32-bit unsigned integers.

This method is not CLS-compliant.  

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

'Declaration
<CLSCompliantAttribute(False)> _
Public Shared Function Min ( _
	val1 As UInteger, _
	val2 As UInteger _
) As UInteger
'Usage
Dim val1 As UInteger
Dim val2 As UInteger
Dim returnValue As UInteger

returnValue = Math.Min(val1, val2)
/** @attribute CLSCompliantAttribute(false) */ 
public static UInt32 Min (
	UInt32 val1, 
	UInt32 val2
)
CLSCompliantAttribute(false) 
public static function Min (
	val1 : uint, 
	val2 : uint
) : uint

Parameters

val1

The first of two 32-bit unsigned integers to compare.

val2

The second of two 32-bit unsigned integers to compare.

Return Value

Parameter val1 or val2, whichever is smaller.
' This example demonstrates Math.Min()
Imports System

Class Sample
   Public Shared Sub Main()
      Dim str As String = "{0}: The lesser 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: SByte, UInt16, UInt32, and UInt64.
      
      Console.WriteLine("{0}Display the lesser of two values:{0}", nl)
      Console.WriteLine(str, "Byte   ", xByte1, xByte2, Math.Min(xByte1, xByte2))
      Console.WriteLine(str, "Int16  ", xShort1, xShort2, Math.Min(xShort1, xShort2))
      Console.WriteLine(str, "Int32  ", xInt1, xInt2, Math.Min(xInt1, xInt2))
      Console.WriteLine(str, "Int64  ", xLong1, xLong2, Math.Min(xLong1, xLong2))
      Console.WriteLine(str, "Single ", xSingle1, xSingle2, Math.Min(xSingle1, xSingle2))
      Console.WriteLine(str, "Double ", xDouble1, xDouble2, Math.Min(xDouble1, xDouble2))
      Console.WriteLine(str, "Decimal", xDecimal1, xDecimal2, Math.Min(xDecimal1, xDecimal2))
      '
      Console.Write("{0}The following types are not supported: ", nl)
      Console.WriteLine("SByte, UInt16, UInt32, and UInt64.")
   End Sub 'Main
End Class 'Sample
'
'This example produces the following results:
'
'Display the lesser of two values:
'
'Byte   : The lesser of   1 and  51 is 1.
'Int16  : The lesser of  -2 and  52 is -2.
'Int32  : The lesser of  -3 and  53 is -3.
'Int64  : The lesser of  -4 and  54 is -4.
'Single : The lesser of   5 and  55 is 5.
'Double : The lesser of   6 and  56 is 6.
'Decimal: The lesser of   7 and  57 is 7.
'
'The following types are not supported: SByte, UInt16, UInt32, and UInt64.
'

// This example demonstrates Math.Min()
import System.*;

class Sample
{
    public static void main(String[] args)
    {
        String str = "{0}: The lesser 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 lesser of two values:{0}", nl);
        Console.WriteLine(str, 
            new Object[] { "Byte   ", (SByte)xByte1, (SByte)xByte2, 
            (SByte)System.Math.Min(xByte1, xByte2) });
        Console.WriteLine(str, 
            new Object[] { "Int16  ", (Int16)xShort1, (Int16)xShort2, 
            (Int16)System.Math.Min(xShort1, xShort2) });
        Console.WriteLine(str, 
            new Object[] { "Int32  ", (Int32)xInt1, (Int32)xInt2, 
            (Int32)System.Math.Min(xInt1, xInt2) });
        Console.WriteLine(str, 
            new Object[] { "Int64  ", (Int64)xLong1, (Int64)xLong2, 
            (Int64)System.Math.Min(xLong1, xLong2) });
        Console.WriteLine(str, 
            new Object[] { "Single ", (System.Single)xSingle1, 
            (System.Single)xSingle2, 
            (System.Single)System.Math.Min(xSingle1, xSingle2) });
        Console.WriteLine(str, 
            new Object[] { "Double ", (System.Double)xDouble1, 
            (System.Double)xDouble2, 
            (System.Double)System.Math.Min(xDouble1, xDouble2) });
        Console.WriteLine(str, 
            new Object[] { "Decimal", 
            (System.Decimal)xDecimal1, (System.Decimal)xDecimal2, 
            (System.Decimal)System.Math.Min(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.Min(xSbyte1, xSbyte2) });
        Console.WriteLine(str, 
            new Object[] { "UInt16 ", (UInt16)xUshort1, (UInt16)xUshort2, 
            (UInt16)System.Math.Min(xUshort1, xUshort2) });
        Console.WriteLine(str, 
            new Object[] { "UInt32 ", (UInt32)xUint1, (UInt32)xUint2, 
            (UInt32)System.Math.Min(xUint1, xUint2) });
        Console.WriteLine(str, 
            new Object[] { "UInt64 ", (UInt64)xUlong1, (UInt64)xUlong2, 
            (UInt64)System.Math.Min(xUlong1, xUlong2) });
    } //main
} //Sample

/*
This example produces the following results:

Display the lesser of two values:

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

The following types are not CLS-compliant:

SByte  : The lesser of 101 and 111 is 101.
UInt16 : The lesser of 102 and 112 is 102.
UInt32 : The lesser of 103 and 113 is 103.
UInt64 : The lesser of 104 and 114 is 104.
*/

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

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.