Articles → CSHARP → Complex Struct In C#

Complex Struct In C#






Purpose




x+iy




  1. x and y are real numbers
  2. i is the imaginary unit

Example


using System.Numerics;

// By passing two values to it's constructor
// The first value represents the real part
// The second value represents the imaginary part
Complex complexOne = new Complex(3, 14);
Console.WriteLine("Initializing the complex variable by passing 2 values in the constructor");
Console.WriteLine(complexOne);

Complex complexTwo = 3.14;
Console.WriteLine("Initializing the complex variable assign the double value");
Console.WriteLine(complexTwo);

Console.ReadLine();



Output


Picture showing the output of complex struct in C#
Click to Enlarge




Posted By  -  Karan Gupta
 
Posted On  -  Thursday, February 2, 2023

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250