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.
Jump into concepts and practice - no test required
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.
+ operator do when used between two strings in C#?+ operator with strings+ operator combines two strings by joining them end to end.+. Those operations use other operators or methods.str1 and str2 in C#?+ operator is used to join strings in C#. Other arithmetic operators like -, *, / are invalid for strings.string result = str1 + str2; correctly concatenates and assigns the result.string a = "Hello";
string b = "World";
string c = a + ", " + b + "!";
Console.WriteLine(c);
string first = "Good";
string second = "Morning";
string message = first + second;
message += 5;
Console.WriteLine(message);
string[] words = {"apple", "banana", "cherry"};, which code correctly concatenates them into a single comma-separated string using string.Concat?string.Concat can join multiple strings passed as arguments. To add commas, they must be separate arguments.