I'm a C# newbie so please go easy. I'm writing a simple console app that I'm testing that needs to diplay someone's age but validate their birth year is within a range. I step through the code but it doesn't validate and I can't figure out why. Any help would be greatly appreciated. P.S. I'm using VS 2008.
using System;
public class Age
{
private int year;
private int age;
//constructor
public Age()
{
}//end constructor
public int Year
{
get
{
return year;
}//end get
set
{
if (value >= 1950 && value <= System.DateTime.Today.Year)
year = value;
}//end set
}//end property Year
public void DisplayAge()
{
Console.WriteLine("Enter your year of birth:");
year = Convert.ToInt32(Console.ReadLine());
age = System.DateTime.Today.Year - year;
Console.WriteLine("Age: {0}", age);
}//end DisplayAge
}//end class Age
________________
Test application
________________
using System;
public class AgeTest
{
public static void Main(string[] args)
{
Age myAge = new Age();
myAge.DisplayAge();
}//end Main method
}//end class HealthProfileTest
using System;
public class Age
{
private int year;
private int age;
//constructor
public Age()
{
}//end constructor
public int Year
{
get
{
return year;
}//end get
set
{
if (value >= 1950 && value <= System.DateTime.Today.Year)
year = value;
}//end set
}//end property Year
public void DisplayAge()
{
Console.WriteLine("Enter your year of birth:");
year = Convert.ToInt32(Console.ReadLine());
age = System.DateTime.Today.Year - year;
Console.WriteLine("Age: {0}", age);
}//end DisplayAge
}//end class Age
________________
Test application
________________
using System;
public class AgeTest
{
public static void Main(string[] args)
{
Age myAge = new Age();
myAge.DisplayAge();
}//end Main method
}//end class HealthProfileTest