Attributes
Lesson 3 of 12 in Coddy's Basics of Classes and Objects in C# course.
Attributes (also known as fields) are the values inside the classes.
class Point {
int x = 0;
int y = 2;
}In the above example, we create a class named Point with two attributes, x and y with the values 0 and 2 accordingly.
In order to make the fields accessible outside of the class (we will see more later on) we need to add the public keyword:
class Point {
public int x = 0;
public int y = 2;
}This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Challenge
EasyCreate a class named Coder with two <strong>public</strong> attributes:
- A string typed value named
namewith your name - An integer typed value named
agewith your age
Try it yourself
// Write code hereAll lessons in Basics of Classes and Objects in C#
1Introduction
Introduction