Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to create a string variable named greeting.
DSA C#
string greeting = [1];Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the double quotes around the text.
Using single quotes which are for characters, not strings.
✗ Incorrect
Strings in C# must be enclosed in double quotes to be valid text values.
2fill in blank
mediumComplete the code to get the length of the string greeting.
DSA C#
int length = greeting.[1];Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase length which does not exist.
Using methods like count which are not string properties.
✗ Incorrect
The Length property returns the number of characters in a string in C#.
3fill in blank
hardFix the error in accessing the first character of the string greeting.
DSA C#
char firstChar = greeting[1]0;
Attempts:
3 left
💡 Hint
Common Mistakes
Using dot notation which is for methods or properties.
Using parentheses or braces which cause syntax errors.
✗ Incorrect
Strings in C# are indexed using square brackets [].
4fill in blank
hardFill both blanks to create a substring from greeting starting at index 1 with length 3.
DSA C#
string part = greeting.[1]([2], 3);
Attempts:
3 left
💡 Hint
Common Mistakes
Using IndexOf which finds position, not extracts substring.
Using wrong start index like 0 instead of 1.
✗ Incorrect
Substring method extracts part of a string starting at given index and length.
5fill in blank
hardFill all three blanks to create a dictionary mapping each character in greeting to its index.
DSA C#
var charIndex = new Dictionary<char, int>(); for (int [1] = 0; [2] < greeting.[3]; [1]++) { charIndex[greeting[[1]]] = [1]; }
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Using Count property which does not exist on string.
✗ Incorrect
Use variable i for loop index, compare i with greeting.Length to loop over all characters.
