public DateTime EnterDeparture()
{
DateTime EnterDeparture = new DateTime();
Console.WriteLine("Enter Year:");
EnterDeparture.AddYears(int.Parse(Console.ReadLine()));
return EnterDeparture;
}
Train train = new Train(number, EnterDeparture()); //Train takes DateTime (2nd parameter)
Console.WriteLine(Convert.ToString(train.Departure));
Rusult in console always the same.
What is wrong?
How to declare DateTime in class Train right?
DateTime.AddYears()returns a new DateTime rather than modify the one you call the method on.You need to return that new DateTime, not the old one: