If you have two arrays string[] a and int[] b how can you get a Dictionary<string,int> from it most efficiently and with least code possible? Assume that they contain the same number of elements.
For example, is this the best way?
Dictionary<string,int> vals = new Dictionary<string,int>();
for(int i = 0; i < size; i++)
{
vals.Add(a[i],b[i]);
}
If your goal is to match at positions within the sequences, you can use
Enumerable.Zip.And since you are working with arrays, writing it “longhand” really isn’t all that long. However, you want to validate beforehand the arrays truly are equal in length.
Usually, Linq can result in more expressive, easier to understand code. In this case, it’s arguable the opposite is true.