A class

A class is a group or template definition of the methods and variables that describe an object. In other words, a class is a blueprint, containing the definition of the variables and the methods that are common to all instances of the class called objects.

Let's take a look at the following code example:

public class PetAnimal
{
private readonly string PetName;
private readonly PetColor PetColor;

public PetAnimal(string petName, PetColor petColor)
{
PetName = petName;
PetColor = petColor;
}

public string MyPet() => $"My pet is {PetName} and its color is {PetColor}.";
}

In the preceding code, we have a PetAnimal class that has two private fields called PetName and PetColor, and one method called MyPet().

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.128.94.171