How to pass struct byref and readonly to a function in C#? -
is possible pass struct byref , readonly function? (just t const&
in c++)
struct { public int b; } void func1(ref a) // want make `a` immutable { }
how that?
update
my biggest concern passing (1) immutable state (2) efficiently. second concern mutating state must simple , easy mutable object.
currently doing this. kind of boxing.
class immutablebox<t> t : struct, new() { public readonly t state; immutablebox(t state) { this.state = state; } } struct examplestatea { public string somefield; } void func1(immutablebox<examplestatea> passimmutablestatewithbox) { }
by keeping instance of immutablebox<t>
, can pass immutable object pointer copy, , it's still easy edit state
because state
mutable. gain chance optimize equality comparison pointer comparison.
Comments
Post a Comment