CodeBlanks Logo Icon CodeBlanks

Project design

C# course · Intermediate · Lesson 112/116

Design the skeleton of the intermediate final mini app.

Project: Library application

In this project you will build a library application step by step. Each lesson adds one piece and the previous lesson's solution comes as the starting point. At the end OOP, LINQ and serialization combine into a working console app.

The first lesson defines a Book class with Title and Author properties. Later lessons build on it: a Library, LINQ queries and file saving.

The Book class skeleton

A Book class carries two auto-properties: public string Title { get; set; } and public string Author { get; set; }. This is the simplest form of holding data inside a class.

You create an instance with new Book { Title = "Crime and Punishment", Author = "Dostoevsky" }. The object initializer assigns values to properties; no constructor is needed.

Exercise Define the Book class

Define a Book class with Title and Author string properties. In Main create a Book instance and print its title with Console.WriteLine.

Show example solution
Write class Book { public string Title { get; set; } public string Author { get; set; } }. In Main write var b = new Book { Title = "Crime and Punishment", Author = "Dostoevsky" }; Console.WriteLine(b.Title);
Example solution:
using System;

class Book
{
    public string Title { get; set; }
    public string Author { get; set; }
}

class Program
{
    static void Main()
    {
        var b = new Book { Title = "Crime and Punishment", Author = "Dostoevsky" };
        Console.WriteLine(b.Title);
    }
}

Test yourself

  1. What does a class define?

    • Data and behavior
    • Only variables
    • Only methods
    • Only comments
    Show answer

    Data and behavior — Correct. A class holds both data (properties) and behavior (methods).

  2. Complete the property

    public string Title {____; }
    Show answer
    public string Title {get; }
  3. Match the part to its role

    class
    Type definition
    public
    Access modifier
    string
    Text type
    new
    Create instance

All lessons in Intermediate