none
"??" operator, what does it mean?

    Question

  • I have a question about the ?? operator, I cannot find anywhere what it means.

    Here how I used it:

    1. At first, I had this query that take the lastest datetime value in Check_In columns.

    "select g.OrderByDescending(t => t.Check_In).FirstOrDefault()).ToList();"

    Now, If there is a Null value in the CheckIn field, I want to get the record with the Null Value, I have done this. It works great, but I don't know what "??" means. I know that DateTime.MaxValue will sort the value with the Null value first. But I don't understant the "??".

    "select g.OrderByDescending(t => t.Check_In ?? DateTime.MaxValue).FirstOrDefault()).ToList();"

    Tuesday, July 30, 2013 1:33 PM

Answers

  • Hi Vinvrnyryd;

    The ?? operator is called null-coalescing operator. See the documentation link and it has sample code.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, July 30, 2013 3:35 PM

All replies

  • Hi Vinvrnyryd;

    The ?? operator is called null-coalescing operator. See the documentation link and it has sample code.


    Fernando (MCSD)

    If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Tuesday, July 30, 2013 3:35 PM
  • Hi Vinvrnyryd,

    Since we haven't heard from you for a long time, I temporarily close this case. I mark useful reply as answer. If you have any concerns, please free feel to reopen it or submit a new question. Thanks for your understanding.

    Thanks

    Best Regards


    Starain Chen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, August 05, 2013 12:35 PM