I have two array with string values, and one dictionary, im trying to add values from array1 as key and values from array2 as value in dictionary.
what is best practice in this case?
i have tried following
foreach(var i in array1)
{
foreach(var t in array2)
dictionary.add(i.value, t.value)
}
Well you could do (in .NET 4):
That basically zips together the two arrays, so you end up with a sequence of pairs. You then call the
ToDictionaryextension method, extracting the key and value from each pair.Alternatively, you could do it the old-fashioned way:
In both cases you should make sure the arrays are the same length, of course.