Monday, 19 November 2012

Concatenation

Concatenation in c sharp:

Joining of things together in programming is said to be concatenation. It includes joining of two or more variables to make a long string. Lets take an example.


      private void button1_Click(object sender, EventArgs e)
        {
            //Creating two string variables.

            string First_Name;                      
            string Second_Name;           
            string Name;
         
            // Assigning values to Variables.

            First_Name= textBox1.Text;                    
            Second_Name = textBox2.Text;

            //Concatenating the variables.

            Name = First_Name + Second_Name;
           
            // Out putting the String variable.
            MessageBox.Show("Your Name is" + Name);
           
        }

In this block of Code  we have 
1.Created three string variables
            
            string First_Name;                      
            string Second_Name;           
            string Name;



2.Assigning the values of two of them 
(Firs_Name and Second_Name)

             First_Name=textBox1.Text;                    
             Second_Name = textBox2.Text;

3.Then Concatenating the First_Name & Second_Name


Name = First_Name + Second_Name;

4. Out putting the variable using Message_Box.

             MessageBox.Show ("Your Name is" + Name);


Lets Code:

Now lets create and windows form application for better understanding of Concept of Concatenation. Like before we will proceed step by step.
Step 1:
        Start a Windows Forms Application new Project in C #.
Step 2:
       Now let's add some controls to our Form.
1. First go to toolbox and add one button to your form.
2. Go to toolbox and add two Text boxes to your form.
3. Go to toolbox and add two labels to your form.
4. Change the text of labels by opening their properties.
   (Right clicking on the label and chose properties at the very end).

Our form should look like this.



Step 3:
      Now Double click on the button to give some codes to it.

Step 4:
       Creating three string variables.

            string First_Name;                      
            string Second_Name;           
            string Name;
Step 5: 
         Assigning values to two of Variables.

            First_Name= textBox1.Text;                    
            Second_Name = textBox2.Text;

Step 6:     
           type this code to Concatenating the variables.

            Name = First_Name + Second_Name;

Step 7:
        Now type or paste the following code to output them.          
            
            MessageBox.Show("Your Name is" + Name);
           
        }
Step 8: Now time to run the program. 







No comments:

Post a Comment