Results 1 to 8 of 8

Thread: Operator overloading Issue

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2009
    Location
    Watch Window(Shift+f9)
    Posts
    1,879

    Question Operator overloading Issue

    can anyone tell me ?why it is printing 76 instead of 86. return new Time(first.hours+second.hours, first.minutes + second.minutes);
    here is the following code .what i have written.kindly let me know please...
    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    
    namespace oExample8
    {
        public struct Time
        {
            public Time(int hours, int minutes)
            {
                this.hours = hours;
                this.minutes = minutes;
            }
            int hours, minutes;
            public static Time operator +(Time first, Time second)
            {
                return new Time(first.hours+second.hours, first.minutes + second.minutes);
    
            }
            public static void Main()
            {
                Time start = new Time();
                Time duration = new Time();
                Time finish = new Time();
                start.hours = 12;
                duration.minutes = 10;
                duration.hours = 1;
                duration.minutes = 76;
                finish = start + duration;
                Console.WriteLine("Finish time would be :{0} hours and {1} minutes.", finish.hours, finish.minutes);
                Console.Read();
            }
    
        }
    }
    Last edited by firoz.raj; May 30th, 2011 at 02:08 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width