[ Pobierz całość w formacie PDF ]
.A Timevalue consists of two parts: a number of hours and a number of minutes.Thecode in bold shows how to implement the binary addition operator (+) foradding two Times together, and the binary subtraction operator (-) forsubtracting one Time from another.10 Module 12: Operators, Delegates, and EventsThe unary increment (++) and decrement (--) operators are also shown.Theyadd or subtract one minute from a Time.public struct Time{public Time(int minutes) : this(0, minutes){}public Time(int hours, int minutes){this.hours = hours;this.minutes = minutes;Normalize( );}// Arithmeticpublic static Time operator+(Time lhs, Time rhs){return new Time(lhs.hours + rhs.hours,lhs.minutes + rhs.minutes);}public static Time operator-(Time lhs, Time rhs){return new Time(lhs.TotalMinutes( ) rhs.TotalMinutes( ));}.// Helper methodsprivate void Normalize( ){if (hours
[ Pobierz całość w formacie PDF ]