Famous Insurance company has a requirement to calculate the age of their customer based on the date of birth received as a string from the user. Write a program that receives the customer date of birth in the format (dd-mm-yyyy). Pass this value to a method, 'calculateAge' which returns the calculated age. Keep the method 'static'. Method to implement: public static int calculateAge(string dateOfBirth) Sample Input : Enter the date of birth (dd-mm-yyyy): 22-10-1984 Sample Output: 36

Answer

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
public class Person
{
DateTime dob;
public DateTime Dob
{
get{return dob;}
set{dob=value;}
}
public void DisplayDetails()
{
Console.WriteLine(calculateAge(dob));
}
public static int calculateAge(DateTime dob){
int age=0;
age=DateTime.Now.Year-dob.Year;
return age;

}
}
namespace DateEx1 //DO NOT CHANGE the namespace name
{
public class Program //DO NOT CHANGE the class name
{
public static void Main(string[] args) //DO NOT CHANGE the 'Main' method signature
{
Person person=new Person();
Console.WriteLine("Enter the date of birth (dd-mm-yyyy): ");
person.Dob=Convert.ToDateTime(Console.ReadLine());
person.DisplayDetails();
}
}
}

All c sharp Questions

Ask your interview questions on c-sharp

Write Your comment or Questions if you want the answers on c-sharp from c-sharp Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---