Home > Software engineering >  Method expecting list when I use List<string>
Method expecting list when I use List<string>

Time:12-09

I'm currently using ASP.NET Core 6 and C#, and I want to return string and a list of string from my method, so I try this:

public async Task<(string, List<string>)> Save(IFormFileCollection files)
{
    var fileNames = new List<string>();

    return isUploaded ? ("Ok", fileNames)
                      : ("Look like the image couldn't upload to the storage", fileNames);
}

But I get this error:

enter image description here

Why is it expecting a string if I define a string and a List<string>?

CodePudding user response:

The problem happens because you have declared the class to implement an interface IBlobHelper which includes the Save method. The Save method declared in the interface returns a Task<string>.

Either you have to change the declaration of the Save method in the interface IBlobHelper or add a second Save method to your class that corresponds to the method in the interface.

  •  Tags:  
  • c#
  • Related