扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:谢启东编译 来源:天极开发 2007年11月14日
关键字:
C++/CLI类型 | CLI值类型 |
bool | System::Boolean |
wchar_t | System::Char |
signed char | System::SByte |
unsigned char | System::Byte |
char | System::SByte或 System::Byte |
short int | System::Int16 |
unsigned short int | System::UInt16 |
int | System::Int32 |
unsigned int | System::UInt32 |
long long int | System::Int64 |
unsigned long long int | System::UInt64 |
float | System::Single |
double | System::Double |
Int32::MaxValue Double::Parse("123.45e-1") 10.2f.ToString() (10 + 5.9).ToString() (100).ToString() 100 .ToString() |
using namespace System; public value class Complex { double real; double imag; public: static initonly Complex i; static Complex() { i = Complex(0.0, 1.0); } Complex(double real) { this->real = real; this->imag = 0.0; } Complex(double real, double imag) { this->real = real; this->imag = imag; } property double Real { double get() { return real; } void set(double value) { real = value; } } property double Imag { double get() { return imag; } void set(double value) { imag = value; } } static Complex operator+(Complex z1, Complex z2) { return Complex(z1.real + z2.real, z1.imag + z2.imag); } static Complex operator-(Complex z1, Complex z2) { return Complex(z1.real - z2.real, z1.imag - z2.imag); } String^ ToString() override { if (imag < 0.0) { return String::Format("({0} - {1}i)", real, -imag); } else if (1.0/imag == Double::NegativeInfinity) { return String::Format("({0} - 0.0i)", real); } else { return String::Format("({0} + {1}i)", real, +imag); } } }; |
using namespace System; int main() { Complex c1; Complex c2(12.5); Complex c3(-1.23, -4.5); Complex c4 = c2 + c3; Complex c5 = c2 - c3; Console::WriteLine("c1: {0}", c1); Console::WriteLine("c2: {0}", c2); Console::WriteLine("c3: {0}", c3); Console::WriteLine("c4: {0}", c4); Console::WriteLine("c5: {0}", c5); Console::WriteLine("i: {0}", Complex::i); Console::WriteLine("c3.Real: {0}", c3.Real); Console::WriteLine("c3.Imag: {0}", c3.Imag); } c1: (0 + 0i) c2: (12.5 + 0i) c3: (-1.23 - 4.5i) c4: (11.27 - 4.5i) c5: (13.73 + 4.5i) i: (0 + 1i) c3.Real: -1.23 c3.Imag: -4.5 |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者