Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Newtonsoft.Json;
- namespace Test {
- public class Program {
- public static void Main() {
- string json = "{ \"phones\": { \"personal\": null }, \"birthday\": null }";
- dynamic d = JsonConvert.DeserializeObject(json);
- Console.WriteLine(d.phones.personal == null);
- string s = ""; s += (d.phones.personal ?? "default");
- Console.WriteLine(s + " " + s.Length);
- string ss = d.phones.personal;
- string sss = ""; sss += (ss ?? "default");
- Console.WriteLine(sss + " " + sss.Length);
- Console.WriteLine(d.birthday == null);
- string s4 = ""; s4 += (d.birthday ?? "default");
- Console.WriteLine(s4 + " " + s4.Length);
- string s5 = d.birthday;
- string s6 = ""; s6 += (s5 ?? "default");
- Console.WriteLine(s6 + " " + s6.Length);
- //works, but verbose
- string s7 = "";
- s7 += (d.birthday != null ? d.birthday : "default");
- Console.WriteLine(s7 + " " + s7.Length);
- d = null;
- //also works
- string s8 = d ?? "default";
- Console.WriteLine(s8 + " " + s8.Length);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement