Reputation: 27592
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?
Upvotes: 6
Views: 3402
Reputation: 1500335
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.
Upvotes: 9
Reputation: 87228
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.
Upvotes: 4