Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

naming convention, C# Async method [duplicate]

Should one prefix Async in method names that is going to execute asynchronously. As in MS EF Core all methods that run async have async prefix. But they have sync methods as well without sync prefix.

what are suggestions where some methods are designed to run in parallel as well.

seeking suggestions.

like image 826
Ammar Ali Avatar asked Apr 20 '26 18:04

Ammar Ali


1 Answers

I assume you mean "suffix", not "prefix".

Microsoft uses the "Async" suffix because they are (often) adding asynchronous versions of methods that have already existed for a long time. So there is not much of a choice but to name them differently than the synchronous versions, so adding "Async" makes sense.

If you are creating new methods yourself, then this is what I do:

  • If you will have both asynchronous and synchronous versions of the methods, then name the asynchronous one with "Async".
  • If the only version of the method is asynchronous, then there really is no need to use the "Async" suffix, since the return type makes it clear that it's asynchronous.

In the end, it's up to you. It really makes no functional difference.

like image 197
Gabriel Luci Avatar answered Apr 22 '26 07:04

Gabriel Luci



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!