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

String type and immutability 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 declare a string variable named greeting.

C Sharp (C#)
string greeting = [1];
Drag options to blanks, or click blank then click option'
AHello
B"Hello"
C'Hello'
Dnew String("Hello")
Attempts:
3 left
💡 Hint
Common Mistakes
Using single quotes instead of double quotes for strings.
Not using quotes at all around the text.
2fill in blank
medium

Complete the code to concatenate two strings greeting and name.

C Sharp (C#)
string message = greeting [1] name;
Drag options to blanks, or click blank then click option'
A/
B-
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using subtraction or multiplication operators instead of plus.
Forgetting to add a space between words.
3fill in blank
hard

Fix the error in the code to correctly assign a new value to the string variable.

C Sharp (C#)
string name = "Alice";
name [1] "Bob";
Drag options to blanks, or click blank then click option'
A+=
B==
C=
D===
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of = for assignment.
Using += which appends instead of replacing.
4fill in blank
hard

Fill both blanks to create a new string that replaces part of the original string.

C Sharp (C#)
string original = "Hello World";
string modified = original.[1]("World", [2]);
Drag options to blanks, or click blank then click option'
AReplace
B"C#"
C"CSharp"
DRemove
Attempts:
3 left
💡 Hint
Common Mistakes
Using Remove instead of Replace.
Not putting the new text in quotes.
5fill in blank
hard

Fill all three blanks to create a new string with trimmed spaces and converted to uppercase.

C Sharp (C#)
string messy = "  hello world  ";
string clean = messy.[1]().[2]().[3]();
Drag options to blanks, or click blank then click option'
ATrim
BToUpper
CToLower
DReplace
Attempts:
3 left
💡 Hint
Common Mistakes
Using ToLower instead of ToUpper.
Not trimming spaces before changing case.