英語で読む

次の方法で共有


Math.DivRem メソッド

定義

2 つの数値の商を計算し、出力パラメーターの剰余も返します。

オーバーロード

DivRem(Int64, Int64, Int64)

2 つの 64 ビット符号付き整数の商を計算し、出力パラメーターの剰余も返します。

DivRem(Int32, Int32, Int32)

2 つの 32 ビット符号付き整数の商を計算し、出力パラメーターの剰余も返します。

DivRem(UIntPtr, UIntPtr)

2 つの符号なしネイティブ サイズの数値の商と剰余を生成します。

DivRem(UInt64, UInt64)

2 つの符号なし 64 ビット数値の商と剰余を生成します。

DivRem(UInt32, UInt32)

2 つの符号なし 32 ビット数値の商と剰余を生成します。

DivRem(UInt16, UInt16)

2 つの符号なし 16 ビット数値の商と剰余を生成します。

DivRem(SByte, SByte)

2 つの符号付き 8 ビット数値の商と残りの部分を生成します。

DivRem(Int64, Int64)

商と、2 つの符号付き 64 ビット数値の残りの部分を生成します。

DivRem(Int32, Int32)

2 つの符号付き 32 ビット数値の商と残りの部分を生成します。

DivRem(Int16, Int16)

商と、2 つの符号付き 16 ビット数値の残りの部分を生成します。

DivRem(Byte, Byte)

2 つの符号なし 8 ビット数値の商と剰余を生成します。

DivRem(IntPtr, IntPtr)

商と、符号付きネイティブ サイズの 2 つの数値の残りの部分を生成します。

DivRem(Int64, Int64, Int64)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

2 つの 64 ビット符号付き整数の商を計算し、出力パラメーターの剰余も返します。

C#
public static long DivRem (long a, long b, out long result);

パラメーター

a
Int64

被除数。

b
Int64

除数。

result
Int64

このメソッドが戻るときに、剰余を格納します。

戻り値

指定した数値の商。

例外

b は 0 です。

次の例では、DivRem(Int64, Int64, Int64) メソッドを示します。

C#
using System;

public class Example
{
   public static void Main()
   {
      // Define several positive and negative dividends.
      long[] dividends = { Int64.MaxValue, 13952, 0, -14032,
                           Int64.MinValue };
      // Define one positive and one negative divisor.
      long[] divisors = { 2000, -2000 };

      foreach (long divisor in divisors)
      {
         foreach (long dividend in dividends)
         {
            long remainder;
            long quotient = Math.DivRem(dividend, divisor, out remainder);
            Console.WriteLine(@"{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}",
                              dividend, divisor, quotient, remainder);
         }
      }
   }
}
// The example displays the following output:
//    9,223,372,036,854,775,807 \ 2,000 = 4,611,686,018,427,387, remainder 1,807
//    13,952 \ 2,000 = 6, remainder 1,952
//    0 \ 2,000 = 0, remainder 0
//    -14,032 \ 2,000 = -7, remainder -32
//    -9,223,372,036,854,775,808 \ 2,000 = -4,611,686,018,427,387, remainder -1,808
//    9,223,372,036,854,775,807 \ -2,000 = -4,611,686,018,427,387, remainder 1,807
//    13,952 \ -2,000 = -6, remainder 1,952
//    0 \ -2,000 = 0, remainder 0
//    -14,032 \ -2,000 = 7, remainder -32
//    -9,223,372,036,854,775,808 \ -2,000 = 4,611,686,018,427,387, remainder -1,808

注釈

剰余の値は、剰余演算子の結果と等しくなります。

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

DivRem(Int32, Int32, Int32)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

2 つの 32 ビット符号付き整数の商を計算し、出力パラメーターの剰余も返します。

C#
public static int DivRem (int a, int b, out int result);

パラメーター

a
Int32

被除数。

b
Int32

除数。

result
Int32

このメソッドが戻るときに、剰余を格納します。

戻り値

指定した数値の商。

例外

b は 0 です。

次の例では、DivRem(Int32, Int32, Int32) メソッドを示します。

C#
using System;

public class Example
{
   public static void Main()
   {
      // Define several positive and negative dividends.
      int[] dividends = { Int32.MaxValue, 13952, 0, -14032,
                                     Int32.MinValue };
      // Define one positive and one negative divisor.
      int[] divisors = { 2000, -2000 };

      foreach (int divisor in divisors)
      {
         foreach (int dividend in dividends)
         {
            int remainder;
            int quotient = Math.DivRem(dividend, divisor, out remainder);
            Console.WriteLine(@"{0:N0} \ {1:N0} = {2:N0}, remainder {3:N0}",
                              dividend, divisor, quotient, remainder);
         }
      }
   }
}
// The example displays the following output:
//       2,147,483,647 \ 2,000 = 1,073,741, remainder 1,647
//       13,952 \ 2,000 = 6, remainder 1,952
//       0 \ 2,000 = 0, remainder 0
//       -14,032 \ 2,000 = -7, remainder -32
//       -2,147,483,648 \ 2,000 = -1,073,741, remainder -1,648
//       2,147,483,647 \ -2,000 = -1,073,741, remainder 1,647
//       13,952 \ -2,000 = -6, remainder 1,952
//       0 \ -2,000 = 0, remainder 0
//       -14,032 \ -2,000 = 7, remainder -32
//       -2,147,483,648 \ -2,000 = 1,073,741, remainder -1,648

注釈

剰余の値は、剰余演算子の結果と等しくなります。

こちらもご覧ください

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

DivRem(UIntPtr, UIntPtr)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

重要

この API は CLS 準拠ではありません。

2 つの符号なしネイティブ サイズの数値の商と剰余を生成します。

C#
[System.CLSCompliant(false)]
public static (nuint Quotient, nuint Remainder) DivRem (nuint left, nuint right);
C#
[System.CLSCompliant(false)]
public static (UIntPtr Quotient, UIntPtr Remainder) DivRem (UIntPtr left, UIntPtr right);

パラメーター

left

nuint

被除数。

right

nuint

除数。

戻り値

ValueTuple<nuint,nuint>

商と、指定した数値の剰余。

属性

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(UInt64, UInt64)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

重要

この API は CLS 準拠ではありません。

2 つの符号なし 64 ビット数値の商と剰余を生成します。

C#
[System.CLSCompliant(false)]
public static (ulong Quotient, ulong Remainder) DivRem (ulong left, ulong right);

パラメーター

left
UInt64

被除数。

right
UInt64

除数。

戻り値

商と、指定した数値の剰余。

属性

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(UInt32, UInt32)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

重要

この API は CLS 準拠ではありません。

2 つの符号なし 32 ビット数値の商と剰余を生成します。

C#
[System.CLSCompliant(false)]
public static (uint Quotient, uint Remainder) DivRem (uint left, uint right);

パラメーター

left
UInt32

被除数。

right
UInt32

除数。

戻り値

商と、指定した数値の剰余。

属性

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(UInt16, UInt16)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

重要

この API は CLS 準拠ではありません。

2 つの符号なし 16 ビット数値の商と剰余を生成します。

C#
[System.CLSCompliant(false)]
public static (ushort Quotient, ushort Remainder) DivRem (ushort left, ushort right);

パラメーター

left
UInt16

被除数。

right
UInt16

除数。

戻り値

商と、指定した数値の剰余。

属性

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(SByte, SByte)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

重要

この API は CLS 準拠ではありません。

2 つの符号付き 8 ビット数値の商と残りの部分を生成します。

C#
[System.CLSCompliant(false)]
public static (sbyte Quotient, sbyte Remainder) DivRem (sbyte left, sbyte right);

パラメーター

left
SByte

被除数。

right
SByte

除数。

戻り値

商と、指定した数値の剰余。

属性

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(Int64, Int64)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

商と、2 つの符号付き 64 ビット数値の残りの部分を生成します。

C#
public static (long Quotient, long Remainder) DivRem (long left, long right);

パラメーター

left
Int64

被除数。

right
Int64

除数。

戻り値

商と、指定した数値の剰余。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(Int32, Int32)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

2 つの符号付き 32 ビット数値の商と残りの部分を生成します。

C#
public static (int Quotient, int Remainder) DivRem (int left, int right);

パラメーター

left
Int32

被除数。

right
Int32

除数。

戻り値

商と、指定した数値の剰余。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(Int16, Int16)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

商と、2 つの符号付き 16 ビット数値の残りの部分を生成します。

C#
public static (short Quotient, short Remainder) DivRem (short left, short right);

パラメーター

left
Int16

被除数。

right
Int16

除数。

戻り値

商と、指定した数値の剰余。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(Byte, Byte)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

2 つの符号なし 8 ビット数値の商と剰余を生成します。

C#
public static (byte Quotient, byte Remainder) DivRem (byte left, byte right);

パラメーター

left
Byte

被除数。

right
Byte

除数。

戻り値

商と、指定した数値の剰余。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9

DivRem(IntPtr, IntPtr)

ソース:
Math.cs
ソース:
Math.cs
ソース:
Math.cs

商と、符号付きネイティブ サイズの 2 つの数値の残りの部分を生成します。

C#
public static (nint Quotient, nint Remainder) DivRem (nint left, nint right);
C#
public static (IntPtr Quotient, IntPtr Remainder) DivRem (IntPtr left, IntPtr right);

パラメーター

left

nint

被除数。

right

nint

除数。

戻り値

ValueTuple<nint,nint>

商と、指定した数値の剰余。

適用対象

.NET 9 およびその他のバージョン
製品 バージョン
.NET 6, 7, 8, 9