Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can use the single <code>|</code> for OR:</p> <pre><code> if (IsFieldEmpty(ref txtFactoryName, true, "Required") | IsFieldEmpty(ref txtShortName, true, "Required") | IsFieldEmpty(ref cboGodown, true, "Required")) { } </code></pre> <p>The double-pipe <code>||</code> is performing <a href="http://en.wikipedia.org/wiki/Short-circuit_evaluation" rel="nofollow noreferrer">short-circuit evaluation</a>, the <a href="http://msdn.microsoft.com/en-us/library/kxszd0kx.aspx" rel="nofollow noreferrer">single version</a> <code>|</code> does full evaluation.<br> The same for <code>&amp;&amp;</code> and <code>&amp;</code>.</p> <p>See the <a href="http://msdn.microsoft.com/en-us/library/kxszd0kx.aspx" rel="nofollow noreferrer">MSDN reference</a>.</p> <p>Response to the <strong>Edit</strong>:</p> <ol> <li>There is no need for the 'ref' in front of txtControl, and removing that would go a long way in addressing the criticism on your approach here. <code>IsFieldEmpty</code> makes no changes to txtControl. You could rename to <code>CheckFieldEmpty</code> to improve it a little further.</li> <li>It is strange that you create an ErrorProvider instance inside this method, does that work at all? There should normally be one (permanent) instance on the Form. You probably want this method to be independent of the Form, so just add an EP as a parameter. It can replace the SetErrorProvider, you can check the EP parameter for null. O, and replace <code>EP.Clear();</code> with <code>Ep.SetErrortxtControl, "");</code></li> </ol>
 

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