-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPair.cs
40 lines (34 loc) · 1.11 KB
/
Pair.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
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace System
{
public struct Pair<A, B>
{
private A first;
private B second;
public A First => first;
public B Second => second;
public Pair(A first, B second)
{
this.first = first;
this.second = second;
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append('[');
if (First != null)
stringBuilder.Append(First.ToString());
stringBuilder.Append(", ");
if (Second != null)
stringBuilder.Append(Second.ToString());
stringBuilder.Append(']');
return stringBuilder.ToString();
}
public static implicit operator KeyValuePair<A, B>(Pair<A, B> pair) => new KeyValuePair<A, B>(pair.First, pair.Second);
public static implicit operator Pair<A, B>(KeyValuePair<A, B> pair) => new Pair<A, B>(pair.Key, pair.Value);
}
}