Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think there is a way to solve it if you relax requirement - have array of entities that would allow modifying set of local <code>int</code> variables via operations on array.</p> <p>To do so it is possible to capture references to the variables in an array of delegates that each take <code>ref int val</code>. </p> <pre><code>void Increase(ref int x) { x++; } void Set(ref int x, int amount) { x = amount; } void Sample() { int a = 10; int b = 20; // Array of "increase variable" delegates var increaseElements = new Action[] { () =&gt; Increase(ref a), () =&gt; Increase(ref b) }; increaseElements[0](); // call delegate, unfortunately () instead of ++ Console.WriteLine(a); // writes 11 // And now with array of "set the variable" delegates: var setElements = new Action&lt;int&gt;[] { v =&gt; Set(ref a,v), v =&gt; Set(ref b,v) }; setElements[0](3); Console.WriteLine(a); // writes 3 } </code></pre> <p>Notes</p> <ul> <li>directly using delegates you have to call them with ().</li> <li>it may be possible to fix <code>()</code> instead of <code>++</code> issue by wrapping delegate into an object that will call Increase as its <code>++</code> implementation....</li> <li>Issue with <code>Set</code> version where one need to call <code>(3)</code> instead of <code>= 3</code> will require more trickery - implementing custom class with indexing to redirect <code>set [index]</code> to call saved setter function.</li> </ul> <p>Warning: This is really done for entertainment purposes - please don't try it in real code.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload