I have many methods similar to this:
void GetColorSky(out float r, out float g, out float b)
void GetColorGround(out float r, out float g, out float b)
“Similar” meaning they have the exact same method header excluding the method name.
I also have several “colourPicker” controls, that accept R, G, B values.
I am trying to create a method that accepts a method as one of it’s parameters, like so:
UpdateColourPicker(ColorPicker cp, CustomMethod cMethod)
and call it as follows:
UpdateColourPicker(cpSky, GetColorSky)
UpdateColourPicker(cpGround, GetColorGround)
What is the correct syntax for out and Action together?
I’ve looked at this question but I still haven’t managed.
Thanks!
Taking cue from that linked answer, this will work:
Unfortunately, as stated in the answer to the question you link,
ActionandFuncdo not work withoutandref. This is simply becauseActionandFuncare just delegate definitions stated (quite a few times to offer different overloads) with generics in the BCL. Addingrefandoutvariants would quickly cause re-definition compiler errors.The full sample: