Good day! I am trying to write an anonymous method using lambda expressions which would return an object from an async task. I would like to do this in the constructor, so that is the reason I can't make its parent method async.
The ReadJsonAsync method returns a Session object.
I will show you the relevant code:
Session session;
fileService = new FileService();
session = async () => { return await fileService.ReadJsonAsync() };
Thanks in advance!
Sessiona delegate type? What are you trying to do? - Yuval ItzchakovSessionobject, which makes no sense. You're trying to store a "method returning Session" into a "Session". You should be storing it into a delegate (which is how you store methods). - Raymond Chenreturn await fileService.ReadJsonAsync()is redundant; you can just returnfileService.ReadJsonAsync()directly and remove theasyncmodifier. - Thomas Levesque