my question is how can it be done to control that a person is greater than 25 when that person Enter your date of birth.
public DateTime Fecha
{
get { return fecha; }
set { fecha = value; }
}
my question is how can it be done to control that a person is greater than 25 when that person Enter your date of birth.
public DateTime Fecha
{
get { return fecha; }
set { fecha = value; }
}
You could try this:
public DateTime Fecha
{
get { return fecha; }
set {
int edad = DateTime.Today.AddTicks(-value.Ticks).Year - 1;
if edad>25{
fecha = value;
}
}
}
You can use another property like this:
public DateTime Fecha { get; set; }
public bool IsMayorDeEdad
{
get
{
var today = DateTime.Today;
// Calculate the age.
var age = today.Year - Fecha.Year;
// Go back to the year the person was born in case of a leap year
if (Fecha > today.AddYears(-age)) {age--;}
return age > 25;
}
}