design - why C# does not provide internal helper for passing property as reference? -


This issue is about language design.

Please do not answer the question while reading the entire post! Thank you.

With all helpers present in C # (like Lambadas or automatic properties) it is very strange for me that I can not give property with a reference, suppose I want to do this: / P>

  foo (ref my_class.prop); I get an error because I write instead:  
  {var tmp = my_class.prop; Foo (tmp); My_class.prop = tmp; }  

And now it works. But please keep in mind the two things:

  1. This is a normal template, I have not typed anywhere, only "var", so it applies to all types and number of properties. I

  2. I have to do it again and again, there will be no use - this is mechanical work

The current problem In fact, it kills such useful works as a swap. Normally swap is 3 lines long, but since it has 2 references, it takes it to 5 lines. Of course this is nonsense and I want to call it all by writing "swap" all the time. But it shows that C # can be saved from reusable code, bad

Question

So - if any compiler automatically creates a temporary variable (as I do by hand), and specify values ​​back to values? Is there any danger in it? I am not looking at it so I am curious about what you think that looks like the design of this issue as it looks now.

Cheers,

edit as 280Z28 gave great examples to kill the idea of ​​automatic raping for properties, yet I suppose It is useful to wrap properties with the temporary variables that might be useful:

  swap (inside my_class.prop1, inside my_class.prop2);  

Otherwise, for a real swap, C #: - (

There, for example,

Case 1:

  int x There are a number of assumptions that give you the meaning and behavior of a  ref  parameter Interlocked.Increment (ref x);  

If you can pass an asset in the context of this method, the call will be the same, but it will be

Case 2:

  zero in Summary: A parameter parameter function passes through the address of the memory location. "By reference, the end of the jar (riff bool trigger) {while the trigger!} Sleep (1000);}  

summary: To pass a property, "The implementation of creating a temporary variable will be synonymous to passing meaning, which is the exact behavior that you reject the parameter when creating the referee .


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -