Classes and objects
A class is a blueprint and an object is one thing made from it. Classes bundle data, called fields, with methods that work on that data.
Create an object with new: Book b = new Book();. Then use a dot to set data and call methods: b.Title = "Wonder";
Mark members public so other code can use them. These methods aren't static: each object has its own data, so you call them on an object.
Example
class Dog
{
public string Name;
public void Bark()
{
Console.WriteLine($"{Name} says woof!");
}
}
// inside Main:
Dog rex = new Dog();
rex.Name = "Rex";
rex.Bark();
Output
Rex says woof!
One class can make as many objects as you like, and each one keeps its own data.
Your tasks
0 of 4 done- Define class Car
- Give it a public string Model
- Add a public void Honk() that prints "Beep!"
- Create a Car with new and call Honk()
Tutor
The tutor guides you toward the answer instead of handing it over. It uses your own Claude usage.
Quick check
Which keyword creates a new object in C#?
No problems found. Unclosed tags, missing semicolons and errors show up here in plain words.