Home > OS >  There is no argument given that corresponds to the required formal parameter - c#
There is no argument given that corresponds to the required formal parameter - c#

Time:02-16

I want to get datetime.now and pass like a parameter for api point from this method:

string GenerateRequestUriData(string endpoint, string dateQuery, string num, int statNum)
    {
        DateTime dateNow = DateTime.Now;

        dateQuery = dateNow.ToString("yyyy-MM-dd");

        num = daysBeforeData;

        statNum = getStationNumber;

        string requestUri = endpoint;
        requestUri  = "/hqdataahs/GetData?";
        requestUri  = $"date={dateQuery}&";
        requestUri  = $"num={num}&";
        requestUri  = $"statNum={statNum}&";

        return requestUri;
    }

In other method I try to receive data from API like this:

async void OnButtonClicked(System.Object sender, System.EventArgs e)
    {
        var result = await _restServiceStations.Get_HQ_AHS(GenerateRequestUriData(Constants.EndPoint));
    }

But I receive error:

There is no argument given that corresponds to the required formal parameter 'dateQuery' of 'HQ_AHS.GenerateRequestUriData(string, string, string, int)'

Is there a way to fix this error ?

CodePudding user response:

the signature of GenerateRequestUriData has four parameters

GenerateRequestUriData(string endpoint, string dateQuery, string num, int statNum)

you are only passing ONE

GenerateRequestUriData(Constants.EndPoint)

you either need to pass all the required parameters, or set default values for them

  • Related