user1005310 user1005310 - 3 months ago 9
C# Question

Conditional logic in the class property

public class test
{
public datetime date1 {get;set;}
public datetime date2 {get;set;}
public string status {get;set;}
}


Now the value of property status is calculated
based on the values for date1 and date2

for example,

if date1 > dataetime.today
status ="active"
else
status = "inactive"


I think I need to write the logic in the set of the property status.
How do I achieve this ?

Answer
public class test
{
    public datetime date1 {get;set;}
    public datetime date2 {get;set;}
    public string status {
        get{
            if (date1 > dataetime.today)
               return "active";
            else
               return "inactive" ;
        }
    }
}