TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Maha
NA
600
70.9k
Constructor body
Dec 2 2014 8:06 AM
In this program statement in the constructor method body is expressed in a different way. I wish to know whether this is unique for the
DateTime
only. Problem is highlighted.
using System;
namespace MethodOverloading
{
public class Time1
{
// 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()
{
Console.WriteLine("{0}/{1}/{2} {3}:{4}:{5}", Month, Date, Year, Hour, Minute, Second);
}
// constructors
public Time1(DateTime dt)
{
Year = dt.Year;
Month = dt.Month;
Date = dt.Day;
Hour = dt.Hour;
Minute = dt.Minute;
Second = dt.Second;
}
public Time1(int Year, int Month, int Date, int Hour, int Minute, int Second)
{
this.Year = Year;
this.Month = Month;
this.Date = Date;
this.Hour = Hour;
this.Minute = Minute;
this.Second = Second;
}
}
public class MethodOverloadingTester
{
public void Run()
{
DateTime currentTime = DateTime.Now;
Console.WriteLine(currentTime);
Time1 time1 = new Time1(currentTime);
time1.DisplayCurrentTime();
Time1 time2 = new Time1(2000, 11, 18, 11, 03, 30);
time2.DisplayCurrentTime();
}
static void Main()
{
MethodOverloadingTester t = new MethodOverloadingTester();
t.Run();
Console.Read();
}
}
}
/*
9/17/2008 8:25:28
11/18/2000 11:3:30
*/
Reply
Answers (
8
)
if enter more than 3 times wrong password
Winform: Validating in non-Form class