C#C
C#12mo ago
Faker

OOP - Properties and Fields

Hello guys, sorry to disturb you all, consider the following code:

C#
namespace Classes;

public class BankAccount
{
    public string Number { get; }
    public string Owner { get; set; }
    public decimal Balance { get; }

    public void MakeDeposit(decimal amount, DateTime date, string note)
    {
    }

    public void MakeWithdrawal(decimal amount, DateTime date, string note)
    {
    }
}


Noticed that we didn't defined the fields but only the properties which is used to get and set the variable.

I have some questions.
We didn't declare any fields or constructors, are the fields created automatically behind the scenes? For the constructor, we will be using the default constructor if nothing is provided?
Was this page helpful?