Concept Flow - String concatenation behavior
Start with strings
Apply + operator
Create new string by joining
Assign or use result
End
This flow shows how C# joins strings using the + operator by creating a new combined string.
string a = "Hello"; string b = "World"; string c = a + ", " + b + "!"; Console.WriteLine(c);
| Step | Operation | Operands | Result | Notes |
|---|---|---|---|---|
| 1 | Assign a | "Hello" | a = "Hello" | Variable a set to Hello |
| 2 | Assign b | "World" | b = "World" | Variable b set to World |
| 3 | Concatenate a + ", " | "Hello" + ", " | "Hello, " | First join creates Hello, |
| 4 | Concatenate previous + b | "Hello, " + "World" | "Hello, World" | Second join adds World |
| 5 | Concatenate previous + "!" | "Hello, World" + "!" | "Hello, World!" | Final join adds exclamation |
| 6 | Assign c | Result of step 5 | c = "Hello, World!" | Variable c set to full string |
| 7 | Print c | c | Output: Hello, World! | Console prints the combined string |
| Variable | Start | After Step 1 | After Step 2 | After Step 6 | Final |
|---|---|---|---|---|---|
| a | null | "Hello" | "Hello" | "Hello" | "Hello" |
| b | null | null | "World" | "World" | "World" |
| c | null | null | null | "Hello, World!" | "Hello, World!" |
String concatenation in C# uses + operator. Each + creates a new string (strings are immutable). Original strings stay unchanged. Use + to join multiple strings. Result can be assigned or printed.