Taking the answer from this related answer, this will work:
public delegate void GetColorDel(out float r, out float g, out float b); void UpdateColourPicker(ColorPicker cp, GetColorDel cMethod) { } UpdateColourPicker(cpSky, GetColorSky); UpdateColourPicker(cpGround, GetColorGround);
Unfortunately, as indicated in the answer to your question, Action
and Func
do not work with out
and ref
. This is simply because Action
and Func
are just delegate definitions (quite a few times to offer different overloads) with generics in BCL. Adding ref
and out
options will quickly cause override compiler errors.
Full sample:
class Program { public delegate void GetColorDel(out float r, out float g, out float b); static void Main(string[] args) { UpdateColourPicker(null, GetColorSky); UpdateColourPicker(null, GetColorGround); Console.Read(); } static void GetColorSky(out float r, out float g, out float b) { r = g = b = 0f; Console.WriteLine("sky"); } static void GetColorGround(out float r, out float g, out float b) { r = g = b = 0f; Console.WriteLine("ground"); } static void UpdateColourPicker(object cp, GetColorDel cMethod) { float r, g, b; cMethod(out r, out g, out b); } }
source share