0

Here is the code I'd like to run:

    public async String products()
    {
        string res = await client.GetStringAsync(apiUrl+"/allItems.php");
        
        return res;
    }

But I get an error like this:

The return type of an async method must be void, Task, Task, a task-like type, IAsyncEnumerable, or IAsyncEnumerator
StripeTerminal
C:\Users\Foxx\Documents\StripeTerminal\StripeTerminal\Form1.cs

What do I need to do to fix this?

2
  • There's nothing wrong with the line of code you posted. The error must be on another line. Commented Aug 12, 2022 at 4:02
  • i made a edit of the full function that i have fornow. Commented Aug 12, 2022 at 4:05

1 Answer 1

3

The error you posted says what the issue is. Take a look at your method signature. It's an async method, returning a string. Should be an async method returning a Task of type string.

Your res variable is of type string, that is correct. But an async method should always return a Task, where T is the underlying datatype you wish to return.

Full example is this.

public async Task<string> products()
{
    string res = await client.GetStringAsync(apiUrl+"/allItems.php");
            
    return res;
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.