简体   繁体   中英

How can I make this C# code more efficient?

I have a piece of code as follows: it retrieves a Json string, parses it, and if required sets the value in the specific node:

 JObject jObject = JObject.Parse(JsonString);
 dynamic dModel = jObject;                                
 var url = dModel.Value<string>("Urllink");

How can I change this to something like below by using the ? expression?

 if (string.IsNullOrEmpty(url))
     url = url;
 else
     url = "#_urlString";

How can I make lines 1 - 5 more efficient?

url=string.IsNullOrWhiteSpace(url) ? url : "#_urlString";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM