linux-packaging-mono/mcs/tests/dtest-null-operator-01.cs
Xamarin Public Jenkins f3e3aab35a Imported Upstream version 4.3.2.467
Former-commit-id: 9c2cb47f45fa221e661ab616387c9cda183f283d
2016-02-22 11:00:01 -05:00

57 lines
756 B
C#

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);
}
}