C#|数学。Min()方法

在C#中, Min() 是一个数学类方法,返回两个指定数字中较小的一个。这个方法总是有两个参数,可以通过 更改数据类型 通过的参数如下:

null
  • 数学最小值(字节,字节): 返回两个8位无符号整数中较小的一个。
  • 数学最小值(十进制,十进制): 返回两个十进制数中较小的一个。
  • 数学最小值(双倍,双倍): 返回两个双精度浮点数中较小的一个。
  • 数学最小值(Int16,Int16): 返回两个16位有符号整数中较小的一个。在这里 Int16 短的 数据类型。
  • 数学最小值(Int32,Int32): 返回两个32位有符号整数中较小的一个。在这里 Int32 智力 数据类型。
  • 数学最小值(Int64,Int64): 返回两个64位有符号整数中较小的一个。在这里 Int64 长的 数据类型。
  • 数学最小值(SByte,SByte): 返回两个8位有符号整数中较小的一个。
  • 数学最小(单个,单个): 返回两个单精度浮点数中较小的一个。在这里 仅有一个的 浮动 数据类型。
  • 数学最小值(UInt16,UInt16): 返回两个16位无符号整数中较小的一个。在这里 UInt16 未签名短(ushort) 数据类型。
  • 数学最小值(UInt32,UInt32): 返回两个32位无符号整数中较小的一个。在这里 UInt32 无符号整数(uint) 数据类型。
  • 数学最小值(UInt64,UInt64): 返回两个64位无符号整数中较小的一个。在这里 UInt64 未签名长(ulong) 数据类型。

以上所有方法的通用语法:

public static data_type Min(Data_type first_value, Data_type second_value)

参数:

这些方法始终接受指定数据类型的两个参数。

返回类型: 方法返回参数列表中指定的两个数字中的最小值,返回类型取决于传递的参数类型。 例子:

CSharp

// C# program to demonstrate the
// Math.Min() method
using System;
class GFG {
// Main Method
static void Main()
{
// byte data type
byte b1 = 10, b2 = 15;
// decimal data type
decimal d1 = 1000M, d2 = 1568M;
// double data type
double db1 = 15.896745, db2 = 8.62644598;
// Int16 data type
short sh1 = -96, sh2 = 24;
// Int32 data type
int i1 = 26745236, i2 = 36725413;
// Int64 data type
long l1 = -2534234234234, l2 = -745837587527423;
// sbyte data type
sbyte sb1 = 52, sb2 = 120;
// single data type
float f1 = 8.0f, f2 = 78.78f;
// UInt16 data type
ushort us1 = 5346, us2 = 6437;
// UInt32 data type
uint un1 = 432344637, un2 = 64762738;
// UInt64 data type
ulong ul1 = 34234234, ul2 = 673286478326;
// displaying result
Console.WriteLine( "Math.Min Method (Byte, Byte) = " + Math.Min(b1, b2));
Console.WriteLine( "Math.Min Method (Decimal, Decimal) = " + Math.Min(d1, d2));
Console.WriteLine( "Math.Min Method (Double, Double) = " + Math.Min(db1, db2));
Console.WriteLine( "Math.Min Method (Int16, Int16) = " + Math.Min(sh1, sh2));
Console.WriteLine( "Math.Min Method (Int32, Int32) = " + Math.Min(i1, i2));
Console.WriteLine( "Math.Min Method (Int64, lInt64) = " + Math.Min(l1, l2));
Console.WriteLine( "Math.Min Method (SByte, SByte) = " + Math.Min(sb1, sb2));
Console.WriteLine( "Math.Min Method (Single, Single) = " + Math.Min(f1, f2));
Console.WriteLine( "Math.Min Method (UInt16, UInt16) = " + Math.Min(us1, us2));
Console.WriteLine( "Math.Min Method (UInt32, UInt32) = " + Math.Min(un1, un2));
Console.WriteLine( "Math.Min Method (UInt64, UInt64) = " + Math.Min(ul1, ul2));
}
}


输出:

Math.Min Method (Byte, Byte) = 10Math.Min Method (Decimal, Decimal) = 1000Math.Min Method (Double, Double) = 8.62644598Math.Min Method (Int16, Int16) = -96Math.Min Method (Int32, Int32) = 26745236Math.Min Method (Int64, lInt64) = -745837587527423Math.Min Method (SByte, SByte) = 52Math.Min Method (Single, Single) = 8Math.Min Method (UInt16, UInt16) = 5346Math.Min Method (UInt32, UInt32) = 64762738Math.Min Method (UInt64, UInt64) = 34234234

© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享