6 C# File System

 

This chapter covers

  • Working with The System.IO namespace.
  • Developing with System.IO through Operating Systems
  • Learning the secrets of the String datatype
  • Applying advanced string manipulation techniques
  • Developing the classic "Hangman" application

We finally reached the second part of this book with this chapter. This advancement means that we are officially starting the advanced topics.

Until now, we learned everything about object-oriented programming we need. From this point onwards, we will get into projects that either use advanced real-life topics or are complete usable projects fit for a portfolio that, with a bit more polish, can be a finished product.

And this chapter is just the beginning, with the following chapters introducing asynchronous programming, hashing, and APIS.

Without further delay, what is this chapter's project about? The project consists of a well-known game popular by its name "Hangman". A random word gets displayed, and character by character, we try to guess it. This project will pick random words from a file existing within the user's hard drive and display the unguessed word on the console. The player then tries to guess it letter by letter. This chapter will teach us about the integrated file class from the System.IO namespace and demonstrate its most common use cases. Additionally, it will serve us as a proper introduction to string manipulation.

6.1 The System.IO namespace

6.1.1 System.IO definition

6.1.2 System.IO classes

6.1.3 System.IO structs, enums, and delegates

6.1.4 System.IO for linux and macOS

6.2 String manipulation

6.2.1 The immutability of strings

6.2.2 Verbatim and quoted Strings

6.2.3 String escape sequences

6.2.4 Format Strings

6.2.5 Substrings

6.3 Guess the word

6.3.1 The project

6.3.2 Our Code

6.3.3 Source code

6.4 Summary

6.5 References