■
Note
If you have a background in OOP, you can think of a structure as a “lightweight class type,” given that
structures provide a way to define a type that supports encapsulation, but cannot be used to build a family of
related types (as structures are implicitly sealed). When you need to build a family of related types through inheri-
tance, you will need to make use of class types.
On the surface, the process of defining and using structures is very simple, but as they say, the
devil is in the details. To begin understanding the basics of structure types, create a new project
named FunWithStructures. In C#, structures are created using the struct keyword. Define a new
structure named Point, which defines two member variables of type int and a set of methods to
interact with said data:
struct Point
{
Do'stlaringiz bilan baham: |