C#之运算符重载学习案例
来源:互联网 发布:lomo拍立得知乎 编辑:程序博客网 时间:2024/06/06 18:44
using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace Override_test{ public class ComplexClass { public class complex { private float real; private float img; public complex(float p, float q) //构造函数 { real = p; img = q; } public complex() //构造函数 { real = 0; img = 0; } public void Print() { Console.WriteLine("{0}+{1}i", real, img); } public static complex operator +(complex Lhs, complex rhs) { complex sum = new complex(); sum.real = Lhs.real + rhs.real; sum.img = Lhs.img + rhs.img; return sum; } public static complex operator -(complex Lhs, complex rhs) { complex result = new complex(); result.real = Lhs.real - rhs.real; result.img = Lhs.img - rhs.img; return result; } } static void Main() { complex A = new complex(10.5f, 12.5f); complex B = new complex(8.0f, 4.5f); complex C; Console.Write("Complex Number A:"); A.Print(); Console.Write("Complex Number B:"); B.Print(); C = A + B; Console.Write("\nA+B="); C.Print(); C = A - B; Console.Write("A-B="); C.Print(); } } }
0 0
- C#之运算符重载学习案例
- C#学习:运算符重载
- 【C#学习】运算符重载
- C#之运算符重载
- 运算符重载案例
- C#源码学习之---运算符的重载
- C#学习日记23---多态性 之 运算符重载、方法重载、抽象类、虚方法
- c#学习笔记(七)运算符重载
- C#运算符重载学习总结
- C#语法之运算符重载
- C#运算符重载
- C# - 运算符重载
- C#运算符重载
- c#运算符重载
- C# 运算符重载
- C#运算符重载
- C# 运算符重载
- C#运算符重载
- 第3课 MFC框架程序
- Apache Phoenix的Array类型
- Nginx源代码分析之群惊问题(十七)
- oracle.jbo.RowInconsistentException: JBO-25014: Another user has changed the row with primary key or
- 第4课 简单绘图
- C#之运算符重载学习案例
- 第5课 文本编程
- Maven基础配置—上传jar包到私服
- 主线程消息循环机制本质
- 比较有用的正则
- 第6课 菜单
- Alphabet旗下Nest重组:开发团队并入谷歌
- SpringMVC项目接收Json数据报406错误
- 第7课 对话框1