I know there are different posts related to questions around this topic, but I couldn't find any source on the question I have.
In some scenarios, it would be much easier, if value types behaved as reference types, i.e. they could be modified inside another method.
For example I want to track some value types of type int
and pass several of them to a method, and that method may modify them. And let's assume, that after execution of the method I will need to use the updated values on the caller side. Of course there are multiple ways to achieve this, but the thing is that it would be just much simpler to pass those integers
to a method, that could return void
, yet we still get the updated values of those integers
, as we hold the references.
As far as I know, there are no such wrappers/classes in C# that represent the same experience like the value types do, yet being reference type. (For example for int
, the wrapper still should do ++, --, have the same range, etc.)
So my question is why there is no such alternative in the language? My assumptions are because of the ambiguousness and to have a single straight way to do things. And to get rid of some small headaches of comparing two equal values that are of different types, etc. And in case someone really needs that, he/she can implement that.
What are your thoughts on this topic? And why the language should NOT have that kind of wrappers of the value types?