3 ms·
C# 7 does allow one to shorten that class a bit further. I saw this trick in the MEAP[0] of C# in Depth. public class TestClass { public int X
by tjalfi 9y ago
C# 7 does allow one to shorten that class a bit further. I saw this trick in the MEAP[0] of C# in Depth.
public class TestClass
{
public int X { get; }
public string Y { get; }
public Guid Z { get; }
public TestClass(int x, string y, Guid z) => (X, Y, Z) = (x, y, z);
}
Disclaimer: I don't combine expression-bodied constructors and tuple construction/deconstruction in my code. I will use either feature but the combination seems likely to annoy my coworkers. I also haven't measured the costs of this idiom.
[0] https://www.manning.com/books/c-sharp-in-depth-fourth-edition https://www.manning.com/books/c-sharp-in-depth-fourth-editio...