forked from idg10/prog-cs-8-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (30 loc) · 907 Bytes
/
Copy pathProgram.cs
File metadata and controls
35 lines (30 loc) · 907 Bytes
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
using System.Collections.Immutable;
namespace ImmutableCollections
{
class Program
{
static void Main()
{
Create();
CreateWithBuilder();
}
public static void Create()
{
IImmutableDictionary<int, string> d = ImmutableDictionary.Create<int, string>();
d = d.Add(1, "One");
d = d.Add(2, "Two");
d = d.Add(3, "Three");
System.Console.WriteLine(d[2]);
}
public static void CreateWithBuilder()
{
ImmutableDictionary<int, string>.Builder b =
ImmutableDictionary.CreateBuilder<int, string>();
b.Add(1, "One");
b.Add(2, "Two");
b.Add(3, "Three");
IImmutableDictionary<int, string> d = b.ToImmutable();
System.Console.WriteLine(d[2]);
}
}
}