Does Anyone Know C#? What Is The Question Notation?

Discussion in 'Education & Personal Growth' started by SuiDhaaga, Jan 5, 2022.

  1. SuiDhaaga

    SuiDhaaga IL Hall of Fame

    Messages:
    2,897
    Likes Received:
    2,012
    Trophy Points:
    308
    Gender:
    Female
    I am tracing code to study for a certification.

    Insee something like

    string requestBody = new StreamReader(req.body).ReadToEnd()
    Dynamic data = JsonConvert.DeserializeObject(requestBody)

    if (data?.values == null) …..

    what is the “?” In data?.values

    What should I even Google???
     
    Loading...

  2. Gauri03

    Gauri03 Moderator Staff Member IL Hall of Fame

    Messages:
    6,211
    Likes Received:
    13,034
    Trophy Points:
    445
    Gender:
    Female
    It's the Null-Conditional Operator. It is a way of pre-emptively testing for whether the object (data in this case) is null before accessing its values. Question marks can be used in a bunch of different ways in C#. See here - What does a question mark mean in C# code?
     
    SuiDhaaga likes this.
  3. SuiDhaaga

    SuiDhaaga IL Hall of Fame

    Messages:
    2,897
    Likes Received:
    2,012
    Trophy Points:
    308
    Gender:
    Female

    U r da best!!!!!!!
     

Share This Page