【发布时间】:2014-07-30 18:37:51
【问题描述】:
我有两个长度相同的数组,我需要将第一个用作Key,将第二个用作Value。
我的Key 是唯一的string,而我的Value 是双精度。
我有 6 只水豚。他们的名字是关键,他们的重量是磅。
我当前的代码:
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
};
这是我的数组,我是 KeyValuePair:
var keyValuePair = new KeyValuePair<string, double>(ViewBag.NomeDaCapivara, ViewBag.PesoDeCadaCapivaraDoMeuBalaioDeCapivaras);
它编译完美,但最后它在运行时给了我一个异常:
=> 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.
我该怎么做?
【问题讨论】: