Answer the question
In order to leave comments, you need to log in
How to override ToString for my Date class?
I have my own Date class, but when I want to output values to another class, it displays the Project Name.Data, I read on the Internet that I need to override ToString but I don’t understand how to do it
Here is the Date class code:
internal class Date
{
protected int Year;
protected int Month;
protected int Day;
protected int Hours;
protected int Minutes;
public Date()
{
Year = 2022;
Month = 1;
Day = 11;
Hours = 12;
Minutes = 20;
}
public int GetYear()
{
return Year;
}
public int GetMonth()
{
return Month;
}
public int GetDay()
{
return Day;
}
public int GetHours()
{
return Hours;
}
public int GetMinutes()
{
return Minutes;
}
public void SetYear(int year)
{
Year = year;
}
public void SetMonth(int month)
{
if(Month > 0 && Month <= 12)
{
Month = month;
}
}
public void SetDay(int day)
{
if(Day > 0 && Day <= 31)
{
Day = day;
}
}
public void SetHours(int hours)
{
if(Hours > 0 && Hours <= 24)
{
Hours = hours;
}
}
public void SetMinutes(int minutes)
{
if(Minutes > 0 && Minutes <= 60)
{
Minutes = minutes;
}
}
}
internal class Airplane
{
protected string StartCity;
protected string FinishCity;
protected Date StartDate;
protected Date FinishDate;
public Airplane()
{
StartCity = "London";
FinishCity = "Lviv";
StartDate = new Date();
FinishDate = new Date();
}
public string GetStartCity()
{
return StartCity;
}
public string GetFinishCity()
{
return FinishCity;
}
public Date GetStartDate()
{
return StartDate;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question