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

String interpolation 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 print the variable name using string interpolation.

C Sharp (C#)
string name = "Alice";
Console.WriteLine($"Hello, [1]!");
Drag options to blanks, or click blank then click option'
Aname.ToString()
B"name"
CName
Dname
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable name in quotes, which prints the word instead of the value.
Using incorrect casing for the variable name.
2fill in blank
medium

Complete the code to include the variable age in the output string using string interpolation.

C Sharp (C#)
int age = 30;
Console.WriteLine($"You are [1] years old.");
Drag options to blanks, or click blank then click option'
Aage
B"age"
CAge
Dage.ToString()
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around the variable name, which prints the text instead of the value.
Using incorrect capitalization.
3fill in blank
hard

Fix the error in the string interpolation to correctly print the full name.

C Sharp (C#)
string firstName = "John";
string lastName = "Doe";
Console.WriteLine($"Full name: [1] {{lastName}}");
Drag options to blanks, or click blank then click option'
AfirstName
B"firstName"
CFirstName
DfirstName.ToString()
Attempts:
3 left
💡 Hint
Common Mistakes
Putting the variable name in quotes inside the interpolation.
Using incorrect capitalization of the variable.
4fill in blank
hard

Fill both blanks to create a greeting with the person's name and age using string interpolation.

C Sharp (C#)
string name = "Emma";
int age = 25;
Console.WriteLine($"Hello, [1]! You are [2] years old.");
Drag options to blanks, or click blank then click option'
Aname
Bage
C"age"
D"name"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variable names inside the interpolation.
Mixing up the variables or using incorrect casing.
5fill in blank
hard

Fill all three blanks to print a formatted message with name, age, and city using string interpolation.

C Sharp (C#)
string name = "Liam";
int age = 40;
string city = "Paris";
Console.WriteLine($"Name: [1], Age: [2], City: [3]");
Drag options to blanks, or click blank then click option'
Aname
Bage
Ccity
D"city"
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around variable names, which prints the text instead of values.
Incorrect capitalization of variable names.