Hello Friends,
In this article, I will explain how to solve Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'
In this week, I was working with one C# class where I want to return a string from Task<string> but I was facing one error like "Cannot implicitly convert type 'string' to 'System.Threading.Tasks.Task<string>'".
Please find below solution
Solution
We need to use Task.FromResult to return string from C#.
Please find below example
public async Task<string> GetString()
{
return await Task.FromResult("Hello");
}
Hope this helped you to solve your error
Happy Programming!!
Don’t forget to leave your feedback and comments below!
If you have any query mail me to Sujeet.bhujbal@gmail.com
Happy programming!!
Don’t forget to leave your feedback and comments below!
Regards
Sujeet Bhujbal
--------------------------------------------------------------------------------
Personal Website :-http://sujeetbhujbal.wordpress.com/
CodeProject:-http://www.codeproject.com/Members/Sujit-Bhujbal
Twitter :-http://twitter.com/SujeetBhujbal
------------------------------------------------------------------------------
Excellent article and with lots of information. I really learned a lot here. Do share more like this.
ReplyDeleteAngularJS Web Application Development
AngularJS App Development
Good readding your post
ReplyDelete