here's an example for a lambda expression in c# :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace lambdaTest
{
class Program
{
delegate int getValueOfReference();
static getValueOfReference newReferenceStorage = null;
static void dummy(int valueInteger)
{
newReferenceStorage = () => { return valueInteger; };
//that's how it should look like - but unfortunately doesn't work in c#
//newReferenceStorage = () => { return refInteger; };
}
static void Main(string[] args)
{
int refInteger = 3;
int valueInteger = 4;
dummy(ref refInteger, valueInteger);
valueInteger++;
//when newReferenceStorage is called, the anonymous method is called..
Console.WriteLine("variable : " + valueInteger);
Console.WriteLine("lambda expresssion : " + newReferenceStorage());
//give some time to read the output...
Console.ReadLine();
}
}
}
Meanwhile I was able to further reduce the lines of code required for a experimental method (as mentioned : "at least not user friendly") which allows to store the reference of a value type. Although this method has some drawbacks :
1. the code needed from the user...
int dummyVariable = 3;
EngFun.pan_setvar(
dummyPanel,
1,
1,
delegate() { Reference.acquire(ref dummyVariable); }
);
//or (the same)
EngFun.pan_setvar(
dummyPanel,
1,
1,
() => { Reference.acquire(ref dummyVariable); }
);
2. for each variable that is stored, one thread needs to be created -> overhead
3. the method pins/fixes the position of the variable in the memory, thus it disables the object, of which the variable is a member variable, to be moved from the garbage collector, which isn't preferrable....
My conclusion is that taking a reference from a variable still isn't a solution
One way to deal with this problem would be, to remove the Var object alltogether and replace them with doubles (properties). And to create a special object/class for the panel functions that use a pointer to a variable - like the current Var object. Thus such a special class would only be needed for these panel functions, and everywhere else doubles (properties) would be used...
edit : -> thus the Var object would only be used in the panel functions that need a pointer to a variable..