I tried to define a class. when I assign using
this = blah blah
the compiler reports "this is readonly"
when I change the class to struct, it looks fine, any idea?
this
in a class
refers to the reference; you cannot reassign your own reference, but you can assign fields etc of the current instance.
this
in a struct
refers to the value itself; when you assign this
, just like when you assign to any value-type variable / parameter, it is copying all of the fields over the top (as a memory-copy). That is possible, but is frankly rare to see in the wild. Or, as with classes, you can assign each of the fields separately.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With