Skip to content

Conflicting errors when casting between Func/Action and Delegate #25165

@pilotMike

Description

@pilotMike

Version Used:

Steps to Reproduce:

public delegate void DoSomething();

public class Code
{
    private Action _f;
    public Code(DoSomething f)
    {
        Action doNothing = (() => {});
        _f = f ?? (DoSomething)doNothing;  
        // error: cannot convert between Action and DoSomething
        // explicit cast between Action and DoSomething redundant
    }
}

Expected Behavior:
Should be able to assign or cast matching signature Action/Func to delegate

Actual Behavior:
Get conflicting messages about not being able to convert and the cast being redundant.
Cannot compile.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions