I have two arrays with the same length and I need to use the first as a Key
and the second as a Value
.
My Key
is an unique string
and my Value
is a double.
I have 6 capybaras. Their names will be the key and their weight is the pound.
My current code:
ViewBag.MeuBalaioDeCapivaras = new string[]
{
"Jerimúndia",
"Genoveva",
"Facibulana",
"Carnavala",
"Dentinhos Dourados",
"Creusa"
};
ViewBag.PesoDeCadaCapivaraDoMeuBalaioDeCapivaras = new double[]
{
500.0,
400.0,
250.0,
12.0,
1589.0,
87.3
};
This is my Arrays and I was doing as a KeyValuePair
:
var keyValuePair = new KeyValuePair<string, double>(ViewBag.NomeDaCapivara, ViewBag.PesoDeCadaCapivaraDoMeuBalaioDeCapivaras);
It compiles perfectly, but in the end it gives me an exception, when running:
=> An exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in System.Core.dll but was not handled in user code. Additional information: The best correspondence of the overloaded method.
How can I do what I need?