Facebook Page Twitter Page LinkedIn Page
× C# Tutorial C# Advanced C# Resources


The C# Math CopySign() method is used to return a number with magnitude of first argument and sign of second argument.

Syntax

public static double CopySign (double magnitude, double sign);

Parameters

magnitude Specify a value providing the magnitude of the result.
sign Specify a value providing the sign of the result.

Return Value

Returns a number with magnitude of first argument and sign of second argument.

Example:

In the below example, CopySign() method is used to return a number with magnitude of first argument and sign of second argument.

using System;

class MyProgram {
  static void Main(string[] args) {
    Console.WriteLine(Math.CopySign(-324.1, 4));   
    Console.WriteLine(Math.CopySign(500, -21));
    Console.WriteLine(Math.CopySign(-40.2, -15));  
  }
}

The output of the above code will be:

324.1
-500
-40.2

❮ C# Math Methods