c# (Unity flavour) Action, return value, error thereof

As I understand it (I am not a language mechanic) in c#, Action must return only void. So given

public void teste( String s ) {}
public int pesty( String s ) {}

Then if you have

private Action<String> xx;

You can indeed say xx = teste, but you can never say xx = pesty.

ie, there is no syntax along the lines

private Action ?int?<string> xx

In short (as far as I know, IANALM) in c# Action can only return void. (You can use “Func” if there’s one argument and one return.)

Anyways, I just noticed that if you try xx=pesty, the resulting error in Unity is in fact,

CS0407: A method or delegate string testy(string)' return type does not match delegate void System.Action(string)’ return type

…rather than something more like “you forgot that Actions must return void, dumbass”. This perhaps suggests that maybe you CAN set a return type for Actions, in c# in Unity?

In short, is there anything I’m missing here, thanks!

It’s not C# in Unity only. If you did similar test in VS with non-Unity project, you’d get CS0407 as well. Even in the MSDN info related to this error, you’ll find example with void. Although that example is reverse of the one provided by you.

So I think you’re not missing anything and Action can return void only :slight_smile: