-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRecursivePureStructOperator.cs
More file actions
40 lines (32 loc) · 1 KB
/
Copy pathRecursivePureStructOperator.cs
File metadata and controls
40 lines (32 loc) · 1 KB
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;
public static class Program {
public static void Main (string[] args) {
var a = new CustomType(1);
var b = new CustomType(2);
var c = a;
Console.WriteLine("{0}", a.Equals(a) ? 1 : 0);
Console.WriteLine("{0}", a.Equals(b) ? 1 : 0);
Console.WriteLine("{0}", a.Equals(c) ? 1 : 0);
Console.WriteLine("{0}", a == a ? 1 : 0);
Console.WriteLine("{0}", a == b ? 1 : 0);
Console.WriteLine("{0}", a == c ? 1 : 0);
}
}
public struct CustomType {
public int Value;
public CustomType (int value) {
Value = value;
}
public bool Equals (CustomType rhs) {
return Value == rhs.Value;
}
public static bool operator == (CustomType lhs, CustomType rhs) {
return lhs.Equals(rhs);
}
public static bool operator != (CustomType lhs, CustomType rhs) {
return !lhs.Equals(rhs);
}
public override string ToString () {
return String.Format("{0}", Value);
}
}