在下面的代码中,“data?.name”是什么意思

时间:2016-08-24 22:03:16

标签: xamarin

有人可以在下面的代码中解释data?.name的含义:

public static async Task Run(HttpRequestMessage req,TraceWriter log)

{
    log.Info($"C# HTTP trigger function processed a request. RequestUri={req.RequestUri}");

    // parse query parameter
    string name = req.GetQueryNameValuePairs()
        .FirstOrDefault(q => string.Compare(q.Key, "name", true) == 0)
        .Value;

    // Get request body
    dynamic data = await req.Content.ReadAsAsync<string>();

    // Set name to query string or body data
    name = name ?? data?.name;


    return name == null
        ? req.CreateResponse(HttpStatusCode.BadRequest, "Please pass a name on the query string or in the request body")
        : req.CreateResponse(HttpStatusCode.OK, "Hello " + name));
}

在此链接中使用:https://blog.xamarin.com/creating-a-serverless-backend-for-mobile-apps/

由于

1 个答案:

答案 0 :(得分:3)

那是C#6 Null Conditional运营商

如果data为null,则会阻止data.name抛出异常,而不是返回null