-
Notifications
You must be signed in to change notification settings - Fork 56
/
Copy pathProgram.cs
32 lines (26 loc) · 817 Bytes
/
Program.cs
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
using System;
using System.Collections.Generic;
namespace Indexers
{
class Program
{
static void Main()
{
var numbers = new List<int> { 1, 2, 1, 4 };
numbers[2] += numbers[1];
Console.WriteLine(numbers[0]);
NullConditionalIndex(null);
EquivalentOfNullConditionalIndex(null);
}
private static void NullConditionalIndex(List<string>? objectWithIndexer)
{
string? s = objectWithIndexer?[2];
Console.WriteLine(s ?? "Null");
}
private static void EquivalentOfNullConditionalIndex(List<string>? objectWithIndexer)
{
string? s = objectWithIndexer == null ? null : objectWithIndexer[2];
Console.WriteLine(s ?? "Null");
}
}
}