Class field
In this chapter you will learn:
Add fields to a class
Class can have its own variables. They are called fields.
class Rectangle {
int Width;
int Height;
}
Here the width
and height
are fields of Rectangle type.
Fields can have the following modifiers:
- static
- public
- internal
- private
- protected
- unsafe
- readonly
- volatile
Multiple fields declaration
For the fields with the same type we can declare them together.
class Rectangle{
int Width, Height;
}
They can share the same modifiers as well.
class Rectangle{
public int Width, Height;
}
Next chapter...
What you will learn in the next chapter:
Home » C# Tutorial » Class