28
1
using System;
2
3
public class Program
4
{
5
public struct Point
6
{
7
public Point(double x, double y) {
8
X = x;
9
Y = y;
10
}
11
public double X { get; init; }
12
public double Y { get; init; }
13
public override string ToString() => $"({X}, {Y})";
14
}
15
16
public static void Main()
17
{
18
var p1 = new Point(10, 10);
19
var p2 = p1 with { Y = 12 };
20
Console.WriteLine(p1);
21
Console.WriteLine(p2);
22
23
var a1 = new { X = 10, Y = 10} ;
24
var a2 = a1 with {X = 12 };
25
Console.WriteLine(a1);
26
Console.WriteLine(a2);
27
}
28
}
Cached Result