youtube-code/2022-11-25-Stack-Vs-Heap/Example1/Program.cs

30 lines
602 B
C#
Raw Normal View History

2022-11-25 08:10:54 +00:00
using System;
namespace StackVsHeap1
{
internal class Program
{
static void Main(string[] args)
{
var dateOfBirth = new DateTime(1987, 05, 01);
var age = CalculateAge(dateOfBirth);
Console.WriteLine(age);
}
private static int CalculateAge(DateTime dateOfBirth)
{
var today = DateTime.Today;
var age = today.Year - dateOfBirth.Year;
if (dateOfBirth.Date > today.AddYears(-age))
age--;
return age;
}
}
}