How to trigger a void within a void.

I need to have a void able to to have brackets { } within a void, or right after: Example() {} or Example({});

  public static void IfValueEquals(float isFloat, float ifFloat,/*It says I can't put a void here -->*/ void Action())
        {
       if(isFloat != ifFloat)
            {
                return;
            }
            if (isFloat == ifFloat)
            {
                Action();
            }
        }

If you know of a cleaner way, please share with me.

Thanks in advance.

You’d use one of the C# delegate types. Such as System.Action for a parameterless method (not void, void is the return type).

Eg:

public static void IfValueEquals(float isFloat, float ifFloat, Action conditionDelegate)

And called like so:

public void SomeMethod() {   }

IfValueEquals(someFloat, anotherFloat, SomeMethod);

Or you can use an anonymous method in the method call:

IfValueEquals(someFloat, anotherFloat, () => {
    //logic here
});

For methods that want a return value, you can use System.Func.

Edit: Missed an important point. To invoke the delegate you’d use conditionDelegate?.Invoke();