In the first chapter, we created a basic Hello World program. In this topic, we will extend that program and use it to implement a struct and a class. While doing so, we will analyze the difference between the implementation and use of reference and value type variables. As you are already aware by now, a struct is a value type variable and a class is a reference type variable:
- Open the Console project created in Chapter 1, Learning the Basic Structure of C#, and declare a CoordinatePoint class with just two member attributes of x and y coordinates. Also create two constructors – one without any parameters and one with two parameters. Please refer to the following code implementation for this:
class CoordinatePoint
{
public float xCoordinate;
public float yCoordinate;
public CoordinatePoint()
{
}
public CoordinatePoint(float x,...