0
0
C Sharp (C#)programming~10 mins

String concatenation behavior in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to concatenate two strings and print the result.

C Sharp (C#)
string greeting = "Hello" + [1];
Console.WriteLine(greeting);
Drag options to blanks, or click blank then click option'
A" World"
BWorld
C' World'
D "World"
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes for strings.
Forgetting to put quotes around the string to concatenate.
2fill in blank
medium

Complete the code to concatenate a string and an integer by converting the integer to a string.

C Sharp (C#)
int number = 5;
string message = "Number: " + [1];
Console.WriteLine(message);
Drag options to blanks, or click blank then click option'
AConvert.ToInt32(number)
Bnumber
Cnumber.ToString()
Dnumber + 1
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to concatenate integer directly without conversion.
Using incorrect conversion methods like Convert.ToInt32 which converts to int, not string.
3fill in blank
hard

Fix the error in the code to concatenate strings using the String.Concat method.

C Sharp (C#)
string part1 = "Good";
string part2 = "Morning";
string result = String.Concat(part1, [1]);
Console.WriteLine(result);
Drag options to blanks, or click blank then click option'
Apart2
B"part2"
Cpart2.ToString()
Dpart1 + part2
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variable names, which makes them string literals.
Trying to concatenate inside the method call incorrectly.
4fill in blank
hard

Fill both blanks to create a string interpolation that includes a variable and an expression.

C Sharp (C#)
int apples = 3;
string message = $"I have [1] apples and [2] more.";
Console.WriteLine(message);
Drag options to blanks, or click blank then click option'
Aapples
Bapples + 2
C{apples + 2}
D{apples}
Attempts:
3 left
💡 Hint
Common Mistakes
Not using curly braces inside the interpolated string.
Using variables without braces in an interpolated string.
5fill in blank
hard

Fill all three blanks to build a concatenated string with a variable, a method call, and a literal.

C Sharp (C#)
string name = "Anna";
string greeting = "Hello, " + [1] + ", you have " + [2] + [3];
Console.WriteLine(greeting);
Drag options to blanks, or click blank then click option'
Aname
Bname.ToUpper()
C" apples."
D" apples"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variable names.
Forgetting the period in the string literal.
Not calling the method correctly.