Chapter 3. Namespaces and Classes Organizing your code

Great developers keep their code and data organized.

What’s the first thing you do when you’re creating an app? You think about what it’s supposed to do, whether you’re solving a problem, creating a game, or just having fun. But it’s not always obvious how individual statements fit into your app’s bigger picture...and that’s where classes come in. They let you organize your code around the features you’re creating and the problems the app needs to solve. Classes can help you organize your data, too, by using them to create objects that represent any “thing” your app needs to know about—and the classes that you design serve as “blueprints” for the objects used in your app.

Classes help you organize your code

Let’s be honest...you’re going to write a lot of code throughout this book. And as you keep going through the chapters, your projects will get bigger and bigger. This is a good thing!

Bigger apps present an interesting challenge. The app you built at the end of Chapter 2 had just a few methods. If you create a console app with the same number of methods, there’s no reason not to put them all in Program.cs.

By the time you get to the end of the book, you’ll be creating apps with dozens of methods. If you put all of those methods into one big Program.cs file, you’ll have a hard time remembering which ones do what—and you’ll ...

Get Head First C#, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.