1 Replies - 2289 Views - Last Post: 11 October 2012 - 05:46 PM Rate Topic: -----

#1 pdvasu  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-October 12

Does My SetTime() Method Work?

Posted 11 October 2012 - 03:58 PM

Hi All,
I am new to C Sharp, I know littlebit 'C' and 'C++'. I have a doubt that how the "SetTime" method is working in the following program. Please explain this. Thanks in Advance.


namespace InOutRef
{
public class Time
{
// private member variables
private int Year;
private int Month;
private int Date;
private int Hour;
private int Minute;
private int Second;
// public accessor methods
public void DisplayCurrentTime( )
{
System.Console.WriteLine( "{0}/{1}/{2} {3}:{4}:{5}",
Month, Date, Year, Hour, Minute, Second );
}
public int GetHour( )
{
return Hour;
}
public void SetTime( int hr, out int min, ref int sec )
{
// if the passed in time is >= 30
// increment the minute and set second to 0
// otherwise leave both alone
if ( sec >= 30 )
{
Minute++;
Second = 0;
}
Hour = hr; // set to value passed in
// pass the minute and second back out
min = Minute;
sec = Second;
}
// constructor
public Time( System.DateTime dt )
{
Year = dt.Year;
Month = dt.Month;
Date = dt.Day;
Hour = dt.Hour;
Minute = dt.Minute;
Second = dt.Second;
}
}
public class Tester
{
static void Main( )
{
System.DateTime currentTime = System.DateTime.Now;
Time t = new Time( currentTime );
t.DisplayCurrentTime( );
int theHour = 3;
int theMinute;
int theSecond = 20;
t.SetTime( theHour, out theMinute, ref theSecond );
System.Console.WriteLine(
"the Minute is now: {0} and {1} seconds",
theMinute, theSecond );
theSecond = 40;
t.SetTime( theHour, out theMinute, ref theSecond );
System.Console.WriteLine( "the Minute is now: " +
"{0} and {1} seconds", theMinute, theSecond );
}
}
}


Output:
11/17/2007 14:6:24
the Minute is now: 6 and 24 seconds
the Minute is now: 7 and 0 seconds

This post has been edited by macosxnerd101: 11 October 2012 - 05:09 PM
Reason for edit:: Please use code tags and a descriptive title


Is This A Good Question/Topic? 0
  • +

Replies To: Does My SetTime() Method Work?

#2 Momerath  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1010
  • View blog
  • Posts: 2,444
  • Joined: 04-October 09

Re: Does My SetTime() Method Work?

Posted 11 October 2012 - 05:46 PM

It is doing what you told it to do but I can't tell you if that is what you want it to do. So tell me, is it doing what you want?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1