Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to open a file for reading using StreamReader.
C Sharp (C#)
using System.IO;
var reader = new StreamReader([1]);
string content = reader.ReadToEnd();
reader.Close(); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put the file name in quotes.
Using incorrect capitalization without quotes.
✗ Incorrect
The file path must be a string literal, so it needs to be in quotes.
2fill in blank
mediumComplete the code to write text to a file using StreamWriter.
C Sharp (C#)
using System.IO; using (var writer = new StreamWriter([1])) { writer.WriteLine("Hello World"); }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using the file name without quotes.
Using incorrect capitalization without quotes.
✗ Incorrect
The file path must be a string literal enclosed in double quotes.
3fill in blank
hardFix the error in the code to properly read a line from a file.
C Sharp (C#)
using System.IO; var reader = new StreamReader("data.txt"); string line = reader.[1](); reader.Close();
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using lowercase letters in method names.
Incorrect capitalization causing method not found errors.
✗ Incorrect
The method name is case-sensitive and must be exactly ReadLine with capital R and L.
4fill in blank
hardFill both blanks to create a dictionary with word lengths for words longer than 3 characters.
C Sharp (C#)
var words = new List<string> { "apple", "cat", "banana", "dog" };
var lengths = words.Where(w => w.Length > 3).ToDictionary([1], [2]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a condition as a key or value selector.
Using ToUpper() instead of length for values.
✗ Incorrect
The dictionary keys are the words themselves (w => w), and the values are their lengths (w => w.Length).
5fill in blank
hardFill all three blanks to create a dictionary with uppercase keys and values for words longer than 4 characters.
C Sharp (C#)
var words = new List<string> { "apple", "cat", "banana", "dog" };
var result = words.Where(w => w.Length > [1]).ToDictionary([2], [3]); Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong length filter number.
Swapping keys and values in ToDictionary.
✗ Incorrect
Filter words longer than 4, use uppercase word as key (w => w.ToUpper()), and original word as value (w => w).