Skip to content
Tutorials Center
My learning

Topics

Lesson 36 of 36 ยท Projects and Practice

Practice Exercises and Solutions

Practice VB.NET with ten graded exercises on collections, LINQ, events, binding, files and data access. Try each yourself in VB, then compare with runnable C# reference solutions.

Reading teaches you to recognize code; writing teaches you to produce it. This lesson gives you ten exercises that follow the second half of the course: collections, LINQ, Windows Forms ideas, files, databases and interop. For each one, first write your own VB.NET solution in Visual Studio (or any editor with the .NET SDK), then compare it with the reference.

The VB.NET compiler is not available on this site, so the reference solutions are runnable C# stand-ins; each uses the same .NET classes you would call from VB, so the logic translates directly (see VB.NET and C# side by side). Expected output is shown only where the program prints it.

How to practice

  1. Read the task and write down the inputs and outputs.
  2. Write the simplest version that works; run it.
  3. Test edge cases: empty input, one item, duplicates, bad input.
  4. Only then look at the solution and compare approaches, not just answers.

Exercise 1: Remove duplicates but keep order

Given {3, 1, 3, 2, 1, 4} produce {3, 1, 2, 4}. (Concept: HashSet, LINQ Distinct.)

C# Solution 1

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 2: Word frequency top three

Count the words in a sentence (ignore case) and print the three most frequent, ties broken alphabetically. (Dictionary, LINQ.)

C# Solution 2

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 3: Balanced brackets

Check that ([]{}) is balanced and ([)] is not. (Stack.)

C# Solution 3

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 4: Students above the class average

Given student/score pairs, list the students whose score is above the mean, highest first. (LINQ Average, Where, OrderByDescending.)

C# Solution 4

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 5: Join orders to customers and total per customer

Produce name -> total for customers with orders, plus 0 for those without. (Group Join, lesson here.)

C# Solution 5

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 6: A tiny event system

Create a Thermostat class with a Temperature property that raises TooHot when it exceeds 30. The handler must receive the new value. (Events.)

C# Solution 6

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 7: Notify on change

Write a Person class implementing INotifyPropertyChanged that raises the event only when the value actually changes. (Data binding.)

C# Solution 7

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 8: Read, transform, write

Read lines from a text file, drop blank lines, trim and uppercase each one, and write them to a second file. (Files.)

C# Solution 8

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 9: Filter and sort a DataTable

Create a DataTable of products, then show those costing more than 5, cheapest first, and the sum of all prices. (ADO.NET.)

C# Solution 9

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Exercise 10: Repository with a filter

Write an IRepository<T> with Add and Find(Func<T, bool>), implement it in memory and use it to find all products under 10. (Patterns.)

C# Solution 10

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with Console.ReadLine()), it gets the next line from this box.

Where to go next

  • Rebuild the expense tracker with a SQLite store.
  • Port the C# solutions here to VB.NET and run them in Visual Studio; note every place the syntax made you stop and think.
  • Read other people's VB code: open-source WinForms utilities are a good source.
  • Return to the Visual Basic .NET track page to revisit any chapter.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why does data.Where(seen.Add) remove duplicates?

    The predicate keeps only items that were newly added.
  2. 2. Which structure checks balanced brackets naturally?

    The most recent open bracket must be closed first (LIFO).
  3. 3. What is the best next step after solving an exercise?

    Edge cases and comparison are where the learning happens.
  4. 4. Which LINQ operator keeps customers that have no orders when joining?

    GroupJoin yields one result per left item with a possibly empty group.

Summary

  • Practice means writing your own solution first and comparing second.
  • The exercises reused: HashSet, Dictionary, Stack, LINQ joins and grouping, events, INotifyPropertyChanged, file streams, DataTable and repositories.
  • Always test boundaries and bad input.

Next: Visual Basic .NET track overview