-6
    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
EB.
  • 2,627
  • 8
  • 35
  • 55
  • 2
    This is a ternary operator: https://msdn.microsoft.com/en-us/library/ty67wk28.aspx – dbugger Jun 10 '15 at 14:55
  • Microsoft provides search engine too in addition to C# and MSDN - https://www.bing.com/search?q=c%23%20what%20is%20question%20mark – Alexei Levenkov Jun 10 '15 at 15:01
  • @Rahul how `return ContractConsignee.Schedule` is equivalent to `return return ContractConsignee == null ? null : ContractConsignee.Schedule` ? – Alexei Levenkov Jun 10 '15 at 15:04

2 Answers2

5

? : is the conditional operator.

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

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
2
return (ContractConsignee == null ? null : ContractConsignee.Schedule);

is equivalent to / short form of

if (ContractConsignee == null)
{
    return null;
}
else
{
    return ContractConsignee.Schedule;
}
rageit
  • 3,513
  • 1
  • 26
  • 38