What is this line of code asking?

90 views Asked by At
    public Schedule Schedule
    {
        get
        {
            return (ContractConsignee == null ? null : ContractConsignee.Schedule);
        }
        set
        {
            if (ContractConsignee == null)
            {
                ContractConsignee = new ContractConsignee(Session);
                ContractConsignee.Assignments.Add(this);
            }
            ContractConsignee.Schedule = value;
        }
    }

Someone else wrote this code. I am trying to solve a bug in our system. I'm not familiar with:

 == null ? null : ContractConsignee.Schedule
2

There are 2 answers

0
Glorfindel On

? : is the conditional operator.

If ContractConsignee is null, the getter returns null; otherwise, it will return ContractConsignee.Schedule.

0
rageit On
return (ContractConsignee == null ? null : ContractConsignee.Schedule);

is equivalent to / short form of

if (ContractConsignee == null)
{
    return null;
}
else
{
    return ContractConsignee.Schedule;
}