C-Sharp C#
Intro to Classes
ClassesA class is a way to organize code that makes it cleaner and more efficient. It lets you group related data together, which we can use to create multiple objects.
Imagine we're writing a program to store the name, age, and height of four people. Without using classes, we'd end up with a lot of separate variables, which can get messy and hard to manage:
string name1 = "Bob"; // Person 1
string name2 = "Joe"; // Person 2
string name3 = "Ben"; // Person 3
string name4 = "Smith"; // Person 4
int age1 = 18; // Person 1
int age2 = 22; // Person 2
int age3 = 15; // Person 3
int age4 = 20; // Person 4
double height1 = 1.75; // Person 1
double height2 = 1.98; // Person 2
double height3 = 2.01; // Person 3
double height4 = 1.88; // Person 4Members only
Keep reading this lesson
You've reached the end of the free preview. Unlock the rest of this lesson plus 4 more lessons in C-Sharp C#.
- Unlimited coding questions
- Unlimited access to all classroom material
- Weekly live call for questions and guidance
- 3,000 AI tutor tokens / month
- Personal SQL database (3 MB)
- Progress tracking
Cancel any time.