Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to insert data into Dictionary<Model, List<Model>() using C#

I need to insert few dummy data into the Dictionary, Below is what I have tried.

            var fakesites = new List<Site> { new Site { Id = 1 } };
            var fakedata = new Dictionary<Gateway, List<FeMeasurementValues>>()
            {
                    new Gateway { SiteId = 1, FirmwareVersion = "1.1.1", ConnectivityStatus = GatewayConnectivityStatus.ReadyToConnect },
                    new Gateway { SiteId = 1, FirmwareVersion = "1.1.3", ConnectivityStatus = GatewayConnectivityStatus.Connected },
            };


            GenerateLoRaSignalAnalysisReport(fakesites, fakedata, DateTime.Now);

I get the error saying "There is no argument given that corresponds to the required formal parameter ‘value’ of Dictionary<Gateway, List>.Add(Gateway, List)"

Please help me.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

In C#, to add an element to a dictionary, you need to provide both the key and the value. The key is the first element in the parentheses, and the value is the second element.

In the code you posted, it looks like you are trying to add two Gateway objects as keys to the fakedata dictionary, but you are not providing any values for these keys. This is causing the error message "There is no argument given that corresponds to the required formal parameter ‘value’ of Dictionary<Gateway, List>.Add(Gateway, List)" to be thrown.

To fix the error, you need to provide a value for each key you are adding to the dictionary. For example:

var fakedata = new Dictionary<Gateway, List<FeMeasurementValues>>()
{
    {
        new Gateway { SiteId = 1, FirmwareVersion = "1.1.1", ConnectivityStatus = GatewayConnectivityStatus.ReadyToConnect },
        new List<FeMeasurementValues>()
    },
    {
        new Gateway { SiteId = 1, FirmwareVersion = "1.1.3", ConnectivityStatus = GatewayConnectivityStatus.Connected },
        new List<FeMeasurementValues>()
    }
};

Hope it helps !

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading