Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace ImplicitAndExplicit
- {
- public class Change
- {
- public uint dollar;
- public ushort cent;
- public Change(uint d,ushort c)
- {
- dollar = d;
- cent = c;
- }
- public static explicit operator Change(float f)
- {
- uint dd = (uint)f;
- ushort cc = (ushort)((f - dd) * 100);
- return new Change(dd, cc);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- float f = 35.75f;
- Change ch = (Change)f;
- Console.WriteLine(ch.dollar+ " " + ch.cent);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement