I have read that NameValueCollection allows for duplicate keys to be added, however this does not seem to be the case when I try to use it.
My Code
using (var wb = new WebClient())
{
var data = new NameValueCollection();
var sourceData = (List<Dictionary<string, object>>)dic["mapData"];
var countSource = sourceData.Count;
foreach (var item in (List<Dictionary<string, object>>)dic["mapData"])
{
data.Add("pp", item["Latitude"].ToString() + "," + item["Longitude"].ToString());
}
var dataCount = data.Count;
var response = wb.UploadValues(@"http://dev.virtualearth.net/REST/V1/Imagery/Map/road/?mapArea=" + swLat.ToString() + "," + swLong + "," + neLat + "," + neLong + "&mapSize=800,600&key=" + key, "POST", data);
return this.LargeJson(new { imageData = CreateBase64Image(response) });
}
What I am observing
my sourceData contains 36 items

I am iterating through sourceData and adding items to my NameValueCollection data and add items with the same key "pp"
I was expecting to have 36 items in my data NameValueCollection, but I am only getting 1 and all of my values get appended to the same key.
What am I missing ?
This is the expected behaviour - see the documentation:
If the specified key already exists in the target NameValueCollection instance, the specified value is added to the existing comma-separated list of values in the form "value1,value2,value3". The values are associated with the same key in the target NameValueCollection instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With