C# Program to find Age
March 30, 2017
Below is a C# program to find Age from a Date of Birth. Enjoy!
public class Person { public string Name { get; set; } public Person(DateTime birthdate) { BirthDate = birthdate; } public DateTime BirthDate { get; private set; } public int Age{ get { var timeSpan = DateTime.Today - BirthDate; var years = timeSpan.Days / 365; return years; } } } public class Program { public static void Main(string[] argvs) { var person = new Person(new DateTime(1998,2,14)); Console.WriteLine(person.Age); } }