Fields
This lesson will go into the details of the member variables or fields of a class.
We'll cover the following...
Fields #
As discussed earlier, fields are actually the member variables inside a class. For instance, in a class representing a vending machine, the VendingMachine class might contain the following fields:
- A countof typeintthat stores the count of products available in the machine.
- A capacityof typeintthat stores the maximum number of products the machine can have.
- A moneyCollectedof typeintto store the money it has collected.
- A manufacturerof typestringto store the name of the manufacturer of the machine.
The fields in the VendingMachine class could be defined like this:
Press +  to interact
public class VendingMachine{private int _count;private int _moneyCollected;public int Capacity;public string Manufacturer;}
As it has been already mentioned that declaring public fields is not a good idea when it comes to the security of the code but for ...
 Ask