-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReturnMutatedNestedStruct.cs
More file actions
44 lines (36 loc) · 1.06 KB
/
Copy pathReturnMutatedNestedStruct.cs
File metadata and controls
44 lines (36 loc) · 1.06 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
41
42
43
44
using System;
public static class Program {
public static CustomParentType ReturnMutatedArgument (CustomParentType arg, int i) {
var result = arg;
result.Nested.Value += i;
return result;
}
public static void Main (string[] args) {
var a = new CustomParentType(1);
CustomParentType b = ReturnMutatedArgument(a, 0);
a.Nested.Value = 2;
Console.WriteLine("a={0}, b={1}", a, b);
b = ReturnMutatedArgument(a, 2);
Console.WriteLine("a={0}, b={1}", a, b);
a.Nested.Value = 3;
Console.WriteLine("a={0}, b={1}", a, b);
}
}
public struct CustomParentType {
public CustomType Nested;
public CustomParentType (int value) {
Nested = new CustomType(value);
}
public override string ToString () {
return String.Format("{0}", Nested);
}
}
public struct CustomType {
public int Value;
public CustomType (int value) {
Value = value;
}
public override string ToString () {
return String.Format("{0}", Value);
}
}