is it possible to create properties with async
get
and set
methods?
if yes, how?
if no, how should I call async methods in get
and set
properly?
No. From section 10.15 of the C# 5 spec:
A method (§10.6) or anonymous function (§7.15) with the async modifier is called an async function. In general, the term async is used to describe any kind of function that has the async modifier.
So it's only methods, lambda expressions and anonymous methods that can use the async
modifier.
Personally I'd think it somewhat odd to have a property like that anyway, especially as the property would have had to return Task<T>
rather than T
. A property should usually "feel" pretty lightweight - which doesn't really fit in with async.
No. You can create methods which look like properties (async Task<T> getFoo()
and async Task setFoo(T item)
), but they're not properties per se.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With