Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This is the thing I would do with DRY (Don't repeat yourself)</p> <pre><code>// Make a list of textboxes and string List&lt;Tuple&lt;TextBox, String&gt;&gt; textBoxesTest = new List&lt;Tuple&lt;TextBox, String&gt;&gt;(); // Add the information textBoxesTest.Add(new Tuple&lt;TextBox, String&gt;(textBox2, "Woman")); textBoxesTest.Add(new Tuple&lt;TextBox, String&gt;(textBox3, "People")); // Go through the list foreach(var tuple in textBoxesTest) { // tuple.Item1 is a TextBox // tuple.Item2 is a String if(String.IsNullOrEmpty(tuple.Item1.Text)) { tuple.Item1.Text = String.Format("0 {0}", tuple.Item2); } // if end else { /* do some other with it */ } } // foreach end </code></pre> <p>Don't test string for emptyness with <code>str == ""</code>. Use the <code>String.IsNullOrEmpty(str)</code> method to check this condition. It is faster, because <code>str == ""</code> will create a new String reference to "". Is null or Empty has the condition <code>value == null || value.Length == 0;</code> which will not create instances of a string.</p> <p>Also make no use of String concatenations, because each will be written in the RAM and then needs to concatenate each time it is used. Better make the use of the <code>String.Format(str, args[])</code> method.</p> <p>The above code is well in the issue of maintainability. You just need to add a tuple to the list when adding another textbox "doing the same", and not add if/else algorithm by copy/paste the code. This would be an common error source.</p>
    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. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    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