Skip to footer content
Iron Academy Logo
C# Application
C# Application

Other Categories

Building a C# Class Library Project - Insights from Tim Corey's Lesson

Tim Corey
19m 06s

In this lesson, Tim Corey guides us through the practical process of creating a C# class library, taking us from planning to actual code. Tim emphasizes that planning is essential, but once the planning is complete, it’s time to start building.

In this article, we’ll follow Tim’s exact approach and reasoning, step by step, to understand how a class library is created, organized, and documented in Visual Studio.

Starting the Class Library in Visual Studio

Tim begins by saying that they have been stuck in planning mode for a while, but now they’re finally ready to code. He opens Visual Studio and chooses “Create a new project”, then selects “Class Library”. Tim names it TrackerLibrary and sets the solution name to TournamentTracker.

Tim’s first action inside the new library is to delete the default Class1.cs, explaining that he doesn’t want any default or poorly named files in his project. He says that renaming can cause issues, so he removes it entirely to avoid problems later.

Turning Planning into Code — Adding Classes

Tim explains that the real benefit of planning is that once you’re ready to code, you’re not guessing what data you need. Instead, you’re simply transferring the planned design into actual code.

He mentions that at this point, you’re not thinking about what data is required, but rather you’re verifying names, structures, and whether anything is missing. Tim says this is why planning speeds up the coding process significantly.

Creating the Team Model

Tim adds the first class: TeamModel. He explains that he could name it just Team, but he prefers adding Model at the end to clearly identify it as a data model.

He uses Visual Studio’s prop snippet to generate properties quickly. Tim creates the following properties:

  • ListTeamMembers

  • string TeamName

Tim also explains a key point: he wants TeamMembers to be initialized automatically so that the list is never null. He demonstrates two approaches:

  1. Before C# 6.0:\ Use a constructor to initialize the list.

  2. Since C# 6.0:\ Initialize directly in the property using:

    public List<PersonModel> TeamMembers { get; set; } = new List<PersonModel>();
    

Tim prefers the modern approach because it simplifies the code.

Creating the Person Model

Next, Tim creates PersonModel. Using the prop snippet, he adds properties quickly:

  • string FirstName

  • string LastName

  • string EmailAddress

  • string CellPhoneNumber

Tim points out how fast it is to build models when planning is already done. He also reminds us that the code is now based directly on the planning document.

Creating the Tournament Model

Tim adds the TournamentModel, which includes:

  • string TournamentName

  • decimal EntryFee

  • ListEnteredTeams

  • ListPrizes

  • List<List> Rounds

He highlights how C# understands complex list structures like List<List> and even auto-fills the type when using new.

Adding Prize Model

Tim adds PrizeModel with the following properties:

  • int PlaceNumber

  • string PlaceName

  • decimal PrizeAmount

  • double PrizePercentage

He notes that these values are left with default values for now and can be modified later when needed.

Creating Matchup Models

Tim adds MatchupModel, including:

  • ListEntries

  • TeamModel Winner

  • int MatchupRound

He also ensures the Entries list is initialized automatically, like he did earlier.

Then Tim adds MatchupEntryModel, which includes:

  • TeamModel TeamCompeting

  • double Score

  • MatchupModel ParentMatchup

Tim emphasizes that these models complete the foundation of the class library.

The Class Library is Simple Once Planned

Tim says that once planning is done, building the class library becomes very simple. He stresses that the library’s structure is straightforward because all the design work was already completed.

He reminds us that the key benefit of planning is that coding becomes fast and clean.

Adding XML Comments — Why It Matters

Tim points out that the final step should be documenting the code, especially using XML comments. He admits that commenting is tedious but warns that if you don’t do it now, you probably won’t do it later.

He shows how to create XML comments by typing three slashes (///) above a property. Tim demonstrates writing descriptions like:

  • “Represents one team in the matchup”

  • “Represents the score for this particular team”

  • “Represents the matchup that this team came from as the winner”

Tim explains that XML comments are not just formatted comments — they become part of the code documentation and help other developers understand your classes.

XML Comments Improve Code Usability

Tim demonstrates how XML comments work with IntelliSense. He creates a constructor and adds XML comments for the parameter, showing that the comments appear automatically in IntelliSense.

He compares this to Visual Studio’s built-in Console.WriteLine() description, which comes from Microsoft’s own XML documentation. Tim explains that using XML comments lets you provide the same level of clarity and usability in your own class library.

Final Encouragement

Tim encourages viewers to add XML comments to the rest of the models, even though he doesn’t show the full process due to its repetitive nature.

He concludes by previewing the next lesson: building forms. Tim notes that the forms designed during planning were simple sketches, and now it’s time to make them look more modern and functional.

Conclusion — Tim’s Lesson in a Nutshell

Tim Corey’s lesson shows that creating a C# class library is a matter of translating planning into code. The steps are:

  1. Create the class library project

  2. Add models based on planning

  3. Initialize lists to avoid nulls

  4. Document the code with XML comments

  5. Prepare for building forms next

By following Tim’s method, you build a clean and well-structured class library efficiently and professionally, ready to support the rest of your application.

Hero Worlddot related to Building a C# Class Library Project - Insights from Tim Corey's Lesson
Hero Affiliate related to Building a C# Class Library Project - Insights from Tim Corey's Lesson

Earn More by Sharing What You Love

Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me