Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dtest-null-operator-01.cs « tests « mcs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: de6013ca044e383a23df3a7b1af1fbd577431d27 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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);
	}
}