Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

foreach with multiple DictionaryEntry

Tags:

c#

foreach

I am trying to write to a ListView using the contents of 3 three already existing resx files. Using the following loop with only one of the files yields close to what I want but I need is to use the same loop with multiple DictionaryEntrys. What I am trying to do looks like this..

ResXResourceReader rdr0 = new ResXResourceReader(textPath1.Text + ".resx");
ResXResourceReader rdr1 = new ResXResourceReader(textPath1.Text + ".es.resx");
ResXResourceReader rdr2 = new ResXResourceReader(textPath1.Text + ".fr.resx");

foreach ((DictionaryEntry d in rdr0) && (DictionaryEntry e in rdr1))
{
    string[] row = { d.Key.ToString(), d.Value.ToString(), e.Value.ToString() };
    var listViewItem = new ListViewItem(row);
    listResx.Items.Add(listViewItem);
}
like image 646
rbelliv Avatar asked Feb 18 '23 05:02

rbelliv


1 Answers

The foreach keyword cannot do that.

Instead, you can use the LINQ .Zip() method:

foreach(var item in rdr0.Zip(rdr1, (d, e)
         => new [] { d.Key.ToString(), d.Value.ToString(), e.Value.ToString() }))
like image 186
SLaks Avatar answered Feb 19 '23 20:02

SLaks