© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•13mo ago•
21 replies
Faker

OOP - Properties and Fields

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

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)
    {
    }
}
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Properties vs Fields in C#
C#CC# / help
13mo ago
OOP and REST/JSON Design
C#CC# / help
2y ago
❔ ✅ why properties instead of public fields
C#CC# / help
3y ago
OOP help
C#CC# / help
9mo ago