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:

         private void txtTotalPayment_Validating(object sender, CancelEventArgs e)
         {
             int val1 = 0;
             int val2 = 0;
             int.TryParse(txtTotal.Text, out val1);
             int.TryParse(txtTotalPayment.Text, out val2);
             if (val2 > val1)
             {
                 MessageBox.Show("Total Payment can't be more than grand total", "Input Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                 txtTotalPayment.Text = "";
                 txtPaymentDue.Text = "";
                 txtTotalPayment.Focus();
                 return;
             }
         }