Copying and Pasting cs Code

In cs, like in almost any computer programming language, reading data from a file can be tricky. You add extra lines of code to tell the computer what to do. Sometimes you can copy and paste these lines from other peoples’ code.

For example, you can follow the pattern in this listing:

         public void clearTxt(Control container)
         {
             try
             {
                 //'for each txt as control in this(object).control
                 foreach (Control txt in container.Controls)
                 {
                     //conditioning the txt as control by getting it's type.
                     //the type of txt as control must be textbox.
                     if (txt is TextBox)
                     {
                         //if the object(textbox) is present. The result is, the textbox will be cleared.
                         txt.Text = "";
                     }
                     if (txt is RichTextBox)
                     {
                         txt.Text = "";
                     }
                 }


             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }