stack-vs-heap/Example3/Program.cs

35 lines
749 B
C#
Raw Permalink Normal View History

2024-10-04 13:13:14 +00:00
using System;
namespace StackVsHeap3
{
internal class Program
{
static void Main(string[] args)
{
var maxAge = 99;
var dateOfBirth = new DateTime(1900, 05, 01);
var calculateAge = () =>
{
var today = DateTime.Today;
var age = today.Year - dateOfBirth.Year;
if (dateOfBirth.Date > today.AddYears(-age))
age--;
return age;
};
var age = calculateAge();
if (age >= maxAge)
Console.WriteLine($"Are you sure you are {age}?");
else
Console.WriteLine(age);
}
}
}