Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The ForEach extension method usually isn't worth the bother.</p> <p><a href="http://blogs.msdn.com/ericlippert/archive/2009/05/18/foreach-vs-foreach.aspx" rel="nofollow noreferrer">Eric Lippert has blogged about it</a>, and his philosophical objection to it is that it looks like a side-effect free expression (like most Linq features) but it is actually a side-effecting imperative statement in disguise.</p> <p>If you want to carry out an action for each item on a list, use the foreach statement. That's what it's for.</p> <p>If you want to manipulate lists of actions, then you can do that, but then you want <code>IEnumerable&lt;Action&gt;</code>.</p> <p>For the first part of your code, how about:</p> <pre><code>var errorList = GetResultRows().Where(row =&gt; row.Field&lt;string&gt;("status").Equals("FAILURE", StringComparison.InvariantCultureIgnoreCase) .ToList(); </code></pre> <p>You have a <code>List&lt;string&gt;</code> called excluded books. Use <code>HashSet&lt;string&gt;</code> instead, and you don't need to check if a string is already added to it:</p> <pre><code>var excludedBooks = new HashSet&lt;string&gt;(); foreach (DataRow row in errorList) { if (ToUseBooksList.Contains((string)row["main_book"])) { BookCheckResults.AddRow(string.Format("Error for MainBook {0}, RiskType {1}", row["main_book"], row["risk_type"])); excludedBooks.Add((string)row["main_book"]); } } </code></pre> <p>You can also filter the list with <code>Where</code>:</p> <pre><code>var excludedBooks = new HashSet&lt;string&gt;(); foreach (DataRow row in errorList.Where(r =&gt; ToUseBooksList.Contains((string)r["main_book"])) { BookCheckResults.AddRow(string.Format("Error for MainBook {0}, RiskType {1}", row["main_book"], row["risk_type"])); excludedBooks.Add((string)row["main_book"]); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload