Make Void as a valid return type #4616
-
Right now System.Void is not a valid return type in C#.
In this case Unit just simulates a void return. Are there any restrictios, why Void cannot be a valid return type? |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
I see this as a problem too. People need to implement workarounds like this in every advanced project: https://chtenb.dev/?page=unit-cs I guess adding a Unit type to the standard library would be nice. (like they did in F#) |
Beta Was this translation helpful? Give feedback.
-
Is there a reason you can't just use public async Task Handle(Command request, CancellationToken cancellationToken)
{
var activity = await _context.Activities.FindAsync(request.Activity.Id);
_mapper.Map(request.Activity, activity);
await _context.SaveChangesAsync(cancellationToken);
} |
Beta Was this translation helpful? Give feedback.
System.Void
is not permitted to be used as a generic type argument by the runtime and by the ECMA 335 specification.See: #1604
#696
#2767
#1279
#3288