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