Return to this page about a week after you finish, and again about a month later. Start each time with a blank editor. These challenges are extra review, outside Day 7's time estimate. Rebuilding code from a description is better evidence that you've learned it than recognizing a familiar solution.
Retrieve: declare a StudyTask record, and write a static method that totals the minutes of the tasks not yet done. Include an empty list. Then explain the difference between record and class to an imaginary colleague.
Debug: predict the output of each program below before you run it. Each one contains a classic C# mistake from this week. Explain the cause, then fix it.
string title = " Read ";
title.Trim();
Console.WriteLine($"[{title}]");Check your prediction
[ Read ]int total = 7;
int count = 2;
double average = total / count;
Console.WriteLine(average);Check your prediction
3var original = new List<int> { 1, 2 };
var copy = original;
copy.Add(3);
Console.WriteLine(original.Count);Check your prediction
3using System.Diagnostics;
Debug.Assert(2 + 2 == 5);
Console.WriteLine("All good");Check your prediction
All goodDebug.Assert only exists in a Debug build. This browser builds in Release mode, where every Debug.Assert call is removed, so the false check never runs. With dotnet run on your own machine, which builds Debug by default, the same program stops at the assertion instead. That is why the course writes its own Check helper: it runs in every build.
Transfer: write the method below from a description alone. Pick test cases that would catch && written as ||, and an endpoint left out of the range.
Your turn
Count in range
Implement CountInRange(List<int> values, int low, int high), counting values from low to high inclusive. Check that 0, 1, 10, 11 in 1 to 10 gives 2, that an empty list gives 0, and that a reversed range such as 10 to 1 gives 0. Print Review checks passed if everything passes.
Console.WriteLine("Review checks passed");Hint 1: the idea
A counted value must satisfy both bounds at once.
Hint 2: a first step
Write the method's signature, returning 0, and add the Check helper. Your first check should fail.
Show one solution
int failures = 0;
Check(CountInRange(new List<int> { 0, 1, 10, 11 }, 1, 10) == 2, "counts inclusive bounds");
Check(CountInRange(new List<int>(), 1, 10) == 0, "empty list");
Check(CountInRange(new List<int> { 1, 10 }, 10, 1) == 0, "reversed range");
if (failures == 0)
{
Console.WriteLine("Review checks passed");
}
void Check(bool passed, string name)
{
if (!passed)
{
Console.WriteLine($"FAILED: {name}");
failures++;
}
}
static int CountInRange(List<int> values, int low, int high)
{
int count = 0;
foreach (int value in values)
{
if (value >= low && value <= high)
{
count++;
}
}
return count;
}Review checks passed>= and <= make both ends of the range count, which the first check pins down with 0, 1, 10 and 11. A reversed range needs no special code: no value can be both at least 10 and at most 1, so the count is 0.
Decide what to revisit
If copies and references were unclear, return to Day 5 before you learn anything new; much of C# builds on that distinction. If parsing felt difficult, state the accepted format and what should happen on failure before you add any features. If you could only finish the planner by reading along, try the reading log again from a blank editor.
When you're ready, Intermediate C# covers interfaces, generics, LINQ and saving data, and Advanced C# goes on to async code and concurrency. C and C++ are separate courses here, and despite the name, you don't need either of them to go further with C#.
Completion is saved in this browser only. It does not measure mastery.