diff options
Diffstat (limited to 'mcs/tests/dtest-null-operator-01.cs')
-rw-r--r-- | mcs/tests/dtest-null-operator-01.cs | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/mcs/tests/dtest-null-operator-01.cs b/mcs/tests/dtest-null-operator-01.cs new file mode 100644 index 00000000000..de6013ca044 --- /dev/null +++ b/mcs/tests/dtest-null-operator-01.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Linq; + +class X +{ + public string Prop; + public A A = new A (); +} + +class A +{ + public string B; +} + +class MainClass +{ + static void NullCheckTest () + { + dynamic dyn = null; + dynamic res; + + res = dyn?.ToString (); + res = dyn?.GetHashCode (); + res = dyn?.DD.Length?.GetHashCode (); + + dyn?.ToString (); + + res = dyn?.Prop; + res = dyn?.Prop?.Prop2; + res = dyn?[0]; + } + + static void Test_1 () + { + dynamic dyn = new X (); + dynamic res; + + res = dyn.Prop?.Length; + res = dyn.A.B?.C.D?.E.F; + } + + static dynamic Test_2 (IEnumerable<dynamic> collection) + { + return collection?.FirstOrDefault ().Length; + } + + public static void Main () + { + NullCheckTest (); + + Test_1 (); + Test_2 (null); + } +} + +
\ No newline at end of file |