How would I "package" an instances field in a func or action by method?
What other possibilities are there for keeping references to a specific (value or reference) field in another class? (I know I can just keep a reference to the object itself)
The following is pseudo-code and will not compile.
class TestClass
{
private static bool someField;
private Func<bool> FuncPackage (ref bool field)
{
return () => ( return field; );
}
private void DoSomethingWithPackage (Func<bool> package)
{
if(package())
Console.WriteLine ("true");
else
Console.WriteLine ("false");
}
static void Main(string[] args)
{
someField = false;
Func<bool> package = FuncPackage (ref someField);
DoSomethingWithPackage (package);
}
}