Why is there not such thing as const when passing argument to another method

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

If you pass a custom made object such as a product to another method this
product object can be changed by this receiving method even if the sender
does not allow that.

So does anyone know why there is no such thing implemented in C# language
that can prevent a receiving method to change the received product for
example.

//Tony
 
If you pass a custom made object such as a product to another method this
product object can be changed by this receiving method even if the sender
does not allow that.

So does anyone know why there is no such thing implemented in C# language
that can prevent a receiving method to change the received product for
example.

Personally I believe that C++ const would be very nice to have.

But Anders Hejlsberg thougth otherwise.

In .NET it is all or none.

Either something is mutable and everybody can change its state
or it is immutable and nobody can change state.

As stated above then I miss the finer granularity, but in
a big portion of cases, then you probably should look into
immutable classes/objects.

Arne
 
Back
Top