Click here to Skip to main content
11,925,307 members (59,519 online)
Click here to Skip to main content
Add your own
alternative version


7 bookmarked

An introduction to Complex Struct of dotnet 4.0

, 27 Oct 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
This short article will show some of the benifits that the Complex Struct provides


The Complex struct which resides in System.Numerics assembly is use for representing complex numbers.

For using the Complex struct, we need to Add the System.Numerics assembly to our project

Using the code

Let us see some examples as how it helps us

Example 1: Display the Real,Imaginary,Magnitude and Phase parts

static void Main(string[] args)
	Complex c1 = new Complex(12, 24);
	Complex c2 = new Complex(21, 34);
	string format1 = "Real,Imaginary,Magnitude,Phase part of first Complex is {0}, {1},{2},{3} respectively";
	Console.WriteLine(format1, c1.Real, c1.Imaginary, c1.Magnitude, c1.Phase);
	string format2 = "Real,Imaginary,Magnitude,Phase part of second Complex is {0}, {1},{2},{3} respectively";
	Console.WriteLine(format2, c2.Real, c2.Imaginary, c1.Magnitude, c1.Phase);

The output is


Example 2: Simple Addition of Complex Numbers

static void Main(string[] args)
        Complex c1 = new Complex(12, 24);
        Complex c2 = new Complex(21, 34);
        Complex result = c1 + c2;
        Console.WriteLine("Addition of Complex numbers is {0}", result);

The result being


Addition can also be performed by using the Add method of Complex struct as shown below

Complex.Add(c1, c2)

Likewise, we can do Complex.Subract,Complex.Multiply, Complex.Divide etc.

Example 3: Negation of Complex Number

Complex number negation can be perform by using the minus(-) sign before the complex number

Console.WriteLine("</span />Negation of First Complex numbers is {0}"</span />, -c1);





Example 4: Conjugate of Complex number


conjugates the first complex number

The answer being 12,-24

Example 5: Reciprocal of Complex number


does reciprocate the first complex number.

Example 6: Exponential of Complex number


results into the exponential of the first complex number

Example 7: Trigonometric function of Complex number


yields the sin of the first Complex Number


yields the Cosin of the first Complex Number


yields the Tangent of the first Complex Number

Here is the output


Likewise, there are many other trigonometric functions

Example 8: Find the Log base 10 of Complex Number


gives the result.

Similarly other logarithmic functions are available.


In this article we have seen how the new Complex Struct of .Net Framework 4.0 has helped us in accomplishing complex number operations.

Comments on the topic are highly appreciated for the improvement of the topic.

Thanks for reading the article.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

You may also be interested in...

Comments and Discussions

GeneralMy vote of 4 Pin
Rudra rafiq17-May-11 1:19
memberRudra rafiq17-May-11 1:19 
you could have given more examples and could have gone into more depth
GeneralMy vote of 1 Pin
Hiren Solanki10-Dec-10 3:57
memberHiren Solanki10-Dec-10 3:57 
GeneralMy vote of 1 Pin
Batzen28-Oct-10 2:52
memberBatzen28-Oct-10 2:52 
GeneralMy vote of 1 Pin
SledgeHammer0127-Oct-10 8:25
memberSledgeHammer0127-Oct-10 8:25 
GeneralMy vote of 1 Pin
Argyle4Ever27-Oct-10 5:25
memberArgyle4Ever27-Oct-10 5:25 
GeneralMy vote of 1 Pin
JF201526-Oct-10 19:10
memberJF201526-Oct-10 19:10 
GeneralI haven't down-voted your article Pin
Henry Minute26-Oct-10 13:24
mvpHenry Minute26-Oct-10 13:24 
GeneralRe: I haven't down-voted your article Pin
Niladri_Biswas26-Oct-10 21:47
memberNiladri_Biswas26-Oct-10 21:47 
GeneralMy vote of 2 Pin
Daniel Brännström26-Oct-10 10:41
memberDaniel Brännström26-Oct-10 10:41 
GeneralMy vote of 1 Pin
Selvin26-Oct-10 5:28
memberSelvin26-Oct-10 5:28 
GeneralMy vote of 1 Pin
leppie26-Oct-10 2:54
memberleppie26-Oct-10 2:54 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.151126.1 | Last Updated 27 Oct 2010
Article Copyright 2010 by Niladri_Biswas
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid