fork download
  1. using System;
  2.  
  3. public class Test
  4. {
  5. private static int CalcAge(DateTime now, DateTime bday)
  6. {
  7. int age = now.Year - bday.Year;
  8. if (bday >= now.AddYears(-age)) age--;
  9. return age;
  10. }
  11.  
  12. public static void Main()
  13. {
  14. Console.WriteLine(CalcAge(new DateTime(2003, 2, 28), new DateTime(2000, 2, 29)));
  15. Console.WriteLine(CalcAge(new DateTime(2003, 3, 1), new DateTime(2000, 2, 29)));
  16. Console.WriteLine(CalcAge(new DateTime(2004, 2, 29), new DateTime(2000, 2, 29)));
  17. }
  18. }
Success #stdin #stdout 0.02s 15876KB
stdin
Standard input is empty
stdout
2
3
3