我正在尝试使用此扩展方法将HttpRequest.QueryString转换为:object[]
public static object[] ToObjectArray(this NameValueCollection nvc)
{
var ret = new object[nvc.Count];
var count = 0;
foreach (string s in nvc)
{
var strings = nvc.GetValues(s);
if (strings != null)
{
foreach (string v in strings)
{
ret[count] = new { s = v };
}
}
count++;
}
return ret;
}
var args = request.QueryString.ToObjectArray();
我认为我已经很接近了,但是我遇到了以下异常:
Object of type '<>f__AnonymousType0`1[System.String]'
cannot be converted to type 'System.Object[]'.
我错过了什么?