當前位置: 首頁>>代碼示例>>C#>>正文


C# Math.Min方法代碼示例

本文整理匯總了C#中System.Math.Min方法的典型用法代碼示例。如果您正苦於以下問題:C# Math.Min方法的具體用法?C# Math.Min怎麽用?C# Math.Min使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.Math的用法示例。


在下文中一共展示了Math.Min方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1:

string str = "{0}: The lesser 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 lesser of two values:\n");
   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.WriteLine("\nThe following types are not CLS-compliant:\n");
   Console.WriteLine(str, "SByte  ", xSbyte1, xSbyte2, Math.Min(xSbyte1, xSbyte2));
   Console.WriteLine(str, "UInt16 ", xUshort1, xUshort2, Math.Min(xUshort1, xUshort2));
   Console.WriteLine(str, "UInt32 ", xUint1, xUint2, Math.Min(xUint1, xUint2));
   Console.WriteLine(str, "UInt64 ", xUlong1, xUlong2, Math.Min(xUlong1, xUlong2));
開發者ID:.NET開發者,項目名稱:System,代碼行數:30,代碼來源:Math.Min

輸出:

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.

示例2: Main

//引入命名空間
using System;

public class MainClass {
    public static void Main() {

        int i = 5;
        Console.WriteLine("Math.Min(1,2) = {0}", Math.Min(i, 2.5F));
    }
}
開發者ID:C#程序員,項目名稱:System,代碼行數:10,代碼來源:Math.Min


注:本文中的System.Math.Min方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。