How do you instantiate a complex number?

Answer

The following are the different ways to assign a value to a complex number:

By passing two Double values to its constructor. The first value represents the real, and the second value represents imaginary part of a complex number.
For example,

Complex c1 = new Complex(5, 8); /* It represents (5, 8) */


By assigning a Byte, SByte, Intl6, UIntl6, Int32, UInt32, Int64, UInt64, Single, or Double value to a Complex object. The assigned value represents the real part of the complex number, and its imaginary part becomes 0. For example,

Complex c2 = 15.3; /* It represents (15.3, 0) */


By casting a Decimal or BigInteger value to a Complex object.
For example,

Complex c3 = (Complex) 14.7; /* It represents (14.7, 0) */


Assigning the value returned by an operator to a Complex variable.
For example,

Complex c4 = c1 + c2; /* It represents (20.3, 8) */

All .net Questions

Ask your interview questions on net

Write Your comment or Questions if you want the answers on net from net Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---