- 3
- 0
- 约2.69万字
- 约 42页
- 2016-11-28 发布于河南
- 举报
ProgrammingC#3.0-3-of1
* It is quite common to overload the equality operator(==) to test whether two objects are equal(how ever equality might be defined for your object).C# insists that if you overload the equals(==) operator, you must also overload the not-equals operator (!=).Similarly,the less-than()and greater-than() operators must be paired, as must the less-than or equals (=) and greater-than or equals (=) operators. * Chapter 5. Nesting Classes Example of Nested class * * namespace Nested_Class { public class Fraction { private int numerator; private int denominator; public Fraction(int numerator, int denominator){…} internal class FractionArtist //?嵌套类的定义 { public void Draw(Fraction f) { … } } } //嵌套类的实例化,Fraction如同namespace Fraction.FractionArtist fa = new Fraction.FractionArtist(); fa.Draw(f1); Ch. 6 Operator Overloading 天津大学软件学院 章亦葵 email:zhangyk@ /faculty/zyksoft/ * * Chapter 6. Operator Overloading Introduction Adding standard operators to user defined types. Adding conversion operators to convert user defined types implicitly and explicitly to other types. implicitly : Fraction frdata = 5. * * Fraction theSum = firstFraction.Add(secondFraction) Fraction theSum = firstFraction + secondFraction Chapter 6. Operator Overloading Using the operator Keyword Creating static method to implement operators. Method return values represent the operation result and parameters are operands(操作数) * * public static user-type operator op (user-type lhs, user-type rhs) user-type result = lhs op rhs 实现重载 操作运算的返回值 要重载的 操作符 操作符左边的操作数 操作符右边的操作数 Chapter 6. Operator Overloading Example using operator keyword Suppose uesr type is Fraction, the operation is the sum(+) of two Faction operands. The operator overloading method is: * * theSum = lhs + rhs public static Fraction operator + (Fraction lhs, Fraction rhs) Chapter 6. Operator Overloading Sup
您可能关注的文档
最近下载
- 《我的世界》诉《迷你世界》二审判决书.pdf VIP
- 等比数列说课市名师优质课比赛一等奖市公开课获奖课件.pptx VIP
- 中韩家庭伦理剧对比分析.doc VIP
- 2026-2030中国锌溴电池行业市场发展趋势与前景展望战略分析研究报告.docx
- 2025年等比数列说课课件.pdf VIP
- 短剧演员合同模板(3篇).docx VIP
- 2025年贵州省情省况核心知识点考核复习题库(含答案).docx
- 良品铺子股份有限公司成本控制问题分析.doc VIP
- JB∕T 11164-2021 吊钩抛丸清理机 技术条件.pdf
- 中国专家共识解读:内分泌性高血压继发性高血压院前与急诊诊治指南(2025版)PPT课件.pptx VIP
原创力文档

文档评论(0)