3 ms·
I'm not sure with the semantics of structs for C#. What java is getting in the future is immutable data values where the reference is the value. When you have
by cogman10 1y ago
I'm not sure with the semantics of structs for C#.
What java is getting in the future is immutable data values where the reference is the value.
When you have something like
class Foo {
int a;
int b;
}
var c = new Foo();
in java, effectively the representation of `c` is a reference which ultimately points to the heap storage locations of `a, b`. In C++ terms, you could think of the interactions as being `c->b`.
When values land, the representation of `c` can instead be (the JVM gets to decide, it could keep the old definition for various performance reasons) something like [type, a, b]. Or in C++ terms the memory layout can be analogous to the following:
struct Foo { int a, int b };
struct Foo c;
c.a = 1;
c.b = 2;
- CharlieDigital 1y agoThis seems like C# `record struct` https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/csharp-10.0/record-structs https://learn.microsoft.com/en-us/dotnet/csharp/language-ref...