× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

How to use && operator in foreach loop to iterate 2 collections at the same time

James Jensen
Feb 10, 2015
<p>I'm assuming that your <code>dr1</code>'s rows are supposed to align with <code>dr</code>'s rows.</p> <p>This doesn't involve the <code>&amp;&amp;</code> operator at all, but rather using a LINQ method to combine the values together:</p> <pre><code>var data = dt.Rows.Cast&lt;DataRow&gt;() .Zip(dt1.Rows.Cast&lt;DataRow&gt;(), (dr, dr1) =&gt; new GetData{ week = dr["Week_Number"].ToString() , Total_Created = dr["Total_Created"].ToString() , Total_Open = dr1["Total_Open"].ToString()); lst.AddRange(data); </code></pre> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/27157660/How%20to%20use%20&amp;&amp;%20operator%20in%20foreach%20loop%20to%20iterate%202%20collections%20at%20the%20same%20time/27157751">Stack Overflow</a>.</p>
comments powered by Disqus