Hack Forums
[C#] C# Concatenation [Beginner Level Tutorial] - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [C#] C# Concatenation [Beginner Level Tutorial] (/showthread.php?tid=755070)



C# Concatenation [Beginner Level Tutorial] - Pulser - Oct 20, 2010

C# Concatenation


What Is Concatenation?
In layman's terms, Concatenation is joining two or more things together.

How To Do It In C#?

For Starters, if you have not read my variables tutorial, or you do not know how to setup a variable, please view my thread here.
https://hackforums.net/showthread.php?tid=755046

Lets Get Started!

Begin by creating a new TextBox and a Button, also set up 2 new string variables.
Code
string conc1 = "Hello";
string conc2 = "HackForums";


Underneath this put the following:
Code
textBox1.Text = conc1 + " " + conc2;

textBox1.Text
This is literally the text that is present inside of your textBox.

conc1 + " " + conc2;
conc2 and conc2 are obviously your 2 variables holding your text.

" "
The reason for putting this is because you want a space in between your two words, without it the result would be "HelloHackforums".

+ + +
The reason for using a + operator is simply to join the variables together.

Spoiler (Click to View)

Conclusion:
Concatenation can be used with strings to join things together. It may be hard to think of a way to use it now, but believe me, opportunities present themselves.

Code:
Code
private void button1_Click(object sender, EventArgs e)
        {
            string conc1 = "Hello";
            string conc2 = "HackForums";

            textBox1.Text = conc1 + " " + conc2;
        }