Create Complex number from real and imaginary values in CSharp

Description

The following code shows how to create Complex number from real and imaginary values.

Example


using System;/*ww w .  j  ava  2 s. co m*/
using System.Numerics;

public class Example
{
   public static void Main()
   {
      Complex complex1 = new Complex(1.3, 1.7);
      Complex complex2 = new Complex(8.7, 5.9);

      Console.WriteLine("{0} + {1} = {2}", complex1, complex2, 
                                          complex1 + complex2);
      Console.WriteLine("{0} - {1} = {2}", complex1, complex2, 
                                          complex1 - complex2);
      Console.WriteLine("{0} * {1} = {2}", complex1, complex2, 
                                          complex1 * complex2);
      Console.WriteLine("{0} / {1} = {2}", complex1, complex2, 
                                          complex1 / complex2);
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var