Skip to content

Suggestion: void as a first-class citizen #234

@erik-kallen

Description

@erik-kallen

I don't know if this is possible, but I find that it would often be useful to be allowed to use void as a normal type (which I think is commonly called unit in functional languages).

This means, for example, that delegating methods can look the same whether they return void or not (note that M1 and M2 have syntactically identical definitions):

class C {
    C _wrapped;

    public void M1(int a) {
        return _wrapped.M1(a);
    }

    public int M2(int a) {
        return _wrapped.M2(a);
    }

    public void M3(int a) {
        var result = _wrapped.M3(a);
        DoSomethingElse();
        return result;
    }
}

Especially when doing code generation, this becomes an issue at times.

Bonus points if it would also be possible to treat an Action<T> as equivalent to Func<T, void>.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions