What You'll Learn in This Video
This hands-on tutorial teaches object-oriented programming (OOP) by building a real bank account management application in C#. You'll understand core OOP concepts and see them applied immediately. For a deeper exploration of these fundamentals, refer to the Comprehensive Guide to Object-Oriented Programming (OOP) in C++.
Why OOP Matters
OOP helps you represent real-world objects in your code by modeling their properties (attributes) and behaviors (actions/functions). This approach:
- Makes code reusable and maintainable
- Mirrors how we think about the real world
- Is used in virtually all modern languages (C#, Java, Python, JavaScript, C++, Ruby, Swift, PHP)
If you're curious about how OOP compares with other paradigms, see Understanding My Coding Journey: From Visual Basic to Object-Oriented Programming.
Core OOP Concepts: Classes vs. Objects
| Concept | Definition | Example | |---------|------------|---------| | Class | A blueprint/template | "Person" – defines name, age, nationality | | Object | A concrete instance of a class | "Salina, age 29, from Bosnia" |
Build a Bank Account App
App Features
- View multiple bank accounts in a grid
- Create new accounts (owner name + unique account number)
- Deposit money into any account
- Withdraw money from any account
- Real-time balance updates
For a broader understanding of how this models real-world banking, explore Understanding Bank Balance Sheets: A Comprehensive Guide to T-Accounts.
Project Setup
- Install Visual Studio 2022+ (Community edition is free)
- Install .NET Framework 8.0 (or newer)
- Create a new C# Windows Forms App project
UI Controls Used
| Control | Purpose | Name in Code |
|---------|---------|--------------|
| Label | "Owner" and "Amount" text |, |
| TextBox | Enter owner name | ownerTxt |
| NumericUpDown | Enter deposit/withdraw amount | amountNum |
| DataGridView | Display all accounts | bankAccountsGrid |
| Button (×3) | Create account, deposit, withdraw | createAccountBtn, depositBtn, withdrawBtn |
If you'd like to see a similar approach in another language, check Java Programming: A Comprehensive Guide to Understanding Java and Its Concepts.
Step-by-Step Code Implementation
1. Create the BankAccount Class
public class BankAccount
{
public string Owner { get; set; }
public Guid AccountNumber { get; set; }
public decimal Balance { get; set; }
}
Owner: string (e.g., "Salina Noura")
Notice how properties like Balance directly correspond to accounting concepts covered in the Comprehensive Guide to Basic Accounting: The Complete Accounting Cycle Explained.
hi guys and welcome to my channel in this video you are going to learn objectoriented programming through
practical examples so that you can apply your knowledge and build real applications I will create a series of
videos where I will teach you all of the oop principles through practical examples and this video is the first
video of that Series so in this video you are going to learn what is oop what are classes objects and how to use them
and together we are going to build an interesting application so before we start writing any code you first need to
understand what is oop and why it is important oop stands for objectoriented programming and it is approach in
programming that helps us to represent real objects from Real World in our programs and that way it helps us to
solve real problems and create modern useful applications that you and me use every day because as I said with oop we
can represent real objects from real world together with their properties and their behaviors and we can translate
that into our applications in this video we are going to build an application with C but oop principles and the logic
that you learn are the same in all oop languages which means that principles that you learn in this video can be
applied across all oop languages such as C++ C Java JavaScript python PHP Ruby Swift and many many more languages so
now that you know that oop is approach in programming that helps us to represent objects from Real World in our
applications together with their properties and their behaviors now the question is what are the most important
Concepts in oop two most important Concepts in oop are classes and objects and they help us to represent entities
from Real World in our applications together with their properties and their behaviors a class serves as a blueprint
as a model and a class tells us which properties and which behaviors that entity has and then an object is a
concrete instance of that class let me give you an example of what is class and what is an object a class can be for
example a person each person has certain properties each person needs to have name age birth country weight and so on
so that is a class it's a blueprint an object is a concrete instance of that class for example an object of class
person can be me with all of my properties my name is salinaa my age is 29 my birth country is Bosnia and so on
another object of class person can be you with your name your age your birth country and so on and please let me know
in the comment section what are your properties what is your name age and where are you watching this video from
I'm very interested to know the people who are watching my videos so once more a class serves as a blueprint or a model
and it describes what kind of properties and behaviors objects need to have and then objects are concrete instances of
that class now let me show you how this works on the application that we are going to build today here I have already
finished application that we will later build together and this application is used in order to manage bank accounts in
this grid we already have two bank accounts one is mine this is owner name account number and then this is the
balance of my bank account and then another bank account is from Elon Musk this is his account number and then his
balance and then also I have the option to create a new bank account so let's say Bill Gates and I say create account
so another bank account will be added this is the owner this is the account number and then balance will initially
be zero because we have just created this account and besides that we also have these two buttons option to deposit
money and to withdraw money from bank account so if I select for example my bank account and I say 100 and I click
on deposit that money will be deposited to my balance also if I select another bank account let's say Elon Musk and I
say 200 and I click on withdraw that money will be withdrawn from his bank account so this is an application that
is very easy to use it is very straightforward it is not especially beautiful because I have not added any
colors I have not styled it in any way but it is very functional and in this video we will learn how to build this
application hey there if your goal is to learn programming and start a successful career build interesting and useful
applications and if you enjoy learning from my you videos then you should definitely enroll in my practical
programming course I will take you from beginner to expert in just a few months and I will give you all of the support
and help that you need to achieve your goals in the course you will work on realistic projects you will get access
to a large community of successful developers and everything that you need to learn will be on one place you just
need to follow the plan that I have created for you and those of you who finish the course successfully will get
a special certificate that is going to open a lot of job opportunities for you in the description you can find a coupon
code to save some money and if you're not sure if this course is for you or not we have 7-Day money back guarantee
which means that if you don't like it for any reason you will get all of your money back no questions asked so now
instead of coming up with excuses use this opportunity to finally learn programming and transform your life
because you really have nothing to lose and a lot to gain so first let's explain what is in the background of this
application and how we can build it so in the background we have one class called bank account and that class says
that each bank account needs to have an owner account number and balance those are the properties of each bank account
and then also it needs to have certain behaviors so we need to be able to create a bank account we need to be able
to deposit money and withdraw money from bank account so that is an example of a class in our program and as we said
class serves as a blueprint and it defines what kind of properties and behaviors objects need to have in our
case class defines that each object needs to have owner unique account number and balance those are the
properties and then behaviors that bank accounts need to have is the ability to withdraw money deposit money and to
create new new bank account and then objects of our class are these three instances here they are concrete
examples of bank account class so this is the application that we are going to build together and in order to build
this application together with me you will need to install Visual Studio 2022 or newer Community version is completely
free and I will leave a link in the description that you can use to download it and also you will need to install Net
Framework my recommendation is that you install NET Framework 8.0 because that is the newest version as of filming this
video you can also install some newer version depending on when you are watching the video and also I will leave
a link to download and install it in the description so once you install those two let's open our visual studio and
let's build this application so here is my visual studio let's click on create new project okay and here we are going
to create C Windows forms application make sure that you select C and not some other language
so C Windows forms app select that and click on next and here we will give the name to our application let's say bank
account app and then click on next again and here you will select your framework for me that is
8.0 and then click on create so here is our project and initially we get this form called form one and that is this
empty form here and if I start my application that form will be started but as you can see it is currently
completely empty because we still have not added anything to our form so now let's do that let's add our controls
let's add our grid buttons and so on I will show you this already finished application again so that you can take a
screenshot if you want because now we want to build our application so that it looks the same same as this already
finished application we want to add the same controls and then we will write the code and implement the same behavior so
I will have this already finished application on the other screen and now we will build our application to look
the same and the reason why I picked Windows forms framework is because it gives us an easy way to create all of
those controls that you could see on our form so that we don't have to spend a lot of time doing it manually and in
instead we can focus on writing the code so now let's design our form make sure to open this designer view off your form
and then open toolbox go to view toolbox and here you will get a list of all of the controls that you can simply drag
and drop onto your form so let's first find a label control you can simply drag and drop it onto the form as I said and
here is our label now you probably can not see this text so let me very quickly increase the font right click on the
form go to properties and here you will find font property so simply click on three these three dots and here I will
increase the font to 16 I believe that will be enough okay so let's just shrink this form a little bit like this okay so
now this is our label and what I want to do is I want to change the text that is displayed in this label so simply right
click click on the label go to properties and here you will find text properties so what I want this label to
say is this text so I want it to say owner and when I press enter as you can see the text will be changed so now
let's copy this label and paste it because I want to add another label but the text of this label will be
amount like this okay so those are two labels that we need now let's add other controls let's also add a text box where
we can enter owner's name and then a numerical field where we can enter the amount so let's go back to our toolbox
and here I will find control which is called text box and I will simply drag and drop it on my form and let's just
make it a little bit bigger so this is our text box this is where we will enter owner's name and then let's also add
another control it is called numeric app up down and that is the control where we can enter numbers and I will put it here
these are controls that we will use when we want to enter owner's name and then the amount that we want to withdraw or
deposit to our bank account so that means that we will need to access these two controls from our code and for that
we use their name so if I click on this control here you will notice that it already has a default name it is textbox
one but what I prefer to do is to give meaningful name to all of my controls because that way I can remember it
easily and I will understand my code better so I will call this control owner txt okay that is much better than
textbox one and then I will also change the name of this control here again right click on it go to properties and
here you will find name property and I will call it amount num so amount numerical okay now let's also add our
grid that will serve as a table where we can show all of our bank accounts so let's go back to toolbox and here I will
find control called grid it is called Data grid View and I will simply drag and drop it to my form like this and
let's just make it a little bit bigger like this okay so inside this grid we will show all of our bank accounts so
let's also change the name of this grid control right click on it go to properties and find name property where
is it it is here so instead of data grid view one I will call it bank accounts grid like this and the only thing that
remains is to add three more buttons so let's go back to toolbox here I will find button control and I will drag and
drop it here let's just make it a little a little bit bigger so this is going to be our first button I will copy it and
paste it here because we need two buttons here okay and I also need another button
which I will copy and paste here and we will also need to access these buttons in our code in order to describe their
behavior so I will also change their names so this button here will be called create account BTN
like this and please notice that when I change the name the text of the button will not be changed because we use the
name in the background to access this control and then text property is what the user sees so if you want to change
this text here this button Tre then you need to change the text property so let's find the text property it is here
and here I will say create account and now the text of the button will be changed and now let's do the
same for these two remaining buttons so this button here its text will be deposit that is what the user will see
and then the name that we will use is going to be deposit BTN like this and then this button here
its name is going to be withdraw BTN like this and then the text is going to be simply with
withdraw like this so that is all that you need to do in order to build the user interface of this application and I
can even start this app and this is what we get here we can enter letters here we can enter numbers and then we can click
on these buttons but currently our application doesn't do anything because we still have not written any code so
now let's focus on writing the code let's see how we can create our first class because here in this grid we are
going to show all of our bank accounts so now let's see how we can create a class that will describe how each bank
account should look like so here on your project on your bank accounts app project right click on it and click on
add new item and what we want to add is a class and here you will name your class I will call it bank account
like this and then simply click on ADD so this here is our class it is called bank account and all of the
properties and behaviors that our class has we will write them inside these curly brackets here so as we said bank
account class will have three properties it will have owner property that is the name of the owner that you enter in the
text box on our form and then it will have bank account number which is unique identifier of each bank account and then
third property will be balance so let's now add those three properties to our class so let's say public string owner
and then here I will put get and set inside these curly brackets owner is the first property of our class and it is of
type string because here I'm entering first name and last name of my user and that is in string format and then this
part here this public access modifier and then this get and set inside curly brackets please write them the same way
I'm doing now and then later in this course we are going to explain what is the purpose of this and what is the
purpose of this for now let's just focus on things that are more important now let's also add account number property
so I will simply copy and paste this property here and then change its name let's call it account number like this
it should also have this public and get and set don't change that for now and then it can be of type string but then
you will have to take care yourself to create a unique account number and if you don't want to do that what you can
do is you can use a different type here and that type is called guid and what guid is going to do is it is going to
give you globally unique identifier every time that you request it so you can simply say hey please give me a new
GID and then it will give you a unique ID that you can use as your account number so it is much better to use good
here instead of string and then let's add third property and that is going to be
balance like this and balance is going to be of type decimal because here we want to enter how much money our bank
account has and then also this part here and this part here they stay the same so this is how you create a class it is
called bank account and all of the properties and all of the behaviors of that class you need to write inside
these curly brackets and here we have just added three properties for our class and those are owner which is of
type string and then account number which is of type guid so globally unique identifier and then balance which is of
type decimal so with this we have created our class and there is just one more thing that I want to change here
and that is this internal access modifier so here I also want to say public and as I said later we are going
to explain in detail what these access modifiers mean for now you can just understand that this is a way to prevent
or allow access to our class and right now everything is public which means that we can access everything and then
later in this course we are going to learn different types of access modifiers and how how to use them for
now everything is just going to be public okay so this is our class and now let's create objects of this class now
we want to show objects of this class inside this grid here so we will also create those objects in the code behind
of this form something that I didn't tell you before is that each form consists of three parts and this here
that you can see that is the user interface part part of your form that is the first part the second part of your
form is code behind which means the place where we write the code now how can you find that code behind it's
actually very easy you just open your form and then you press F7 and that will take you to the code behind of your form
and another way if this shortcut doesn't work is to Simply write click on your form and then click on view code and
that will take you to the same place so this here is the place where we write the code and as you can see our form
itself is also a class and you will notice here that it is partial class and what this means is that it consists of
multiple Parts as I already explained this here is one part of our form and then this here is another part of our
form and because of that our form is partial class and then third part of our form is this form 1. designer. Cs and
this file here is automatically generated which means that we should not write any code inside it and we should
not touch it so code behind is the place where we are going to write the code for our form now please take a look at this
method here this is a special type of method called Constructor and Constructor is the first method that
will be invoked when a class is created so when we start our application this is the form that will be started
and in order to construct this form what our operating system will do is it will invoke its Constructor so this method
here will be executed when our form starts which means that inside this method inside this Constructor we can
put any code that we would like to execute when our form starts so what I would like to do is I would like to
create a few objects of bank account class and then show them inside my grid now there are different ways and
different approaches to do this but for now let's go with the easiest approach so we will write the code here inside
the Constructor of form one let's see how we can create an object of bank account class so you simply say bank
account so the name of your class and then you give the name to your object my object will be called called bank
account with lowercase letters and then I will simply say please create new bank account like this so this is very
similar to creating normal regular variables you first specify the type of your variable and then you give the name
to your variable and then in case of objects you also need to say that you want to create a new object of that type
and for now it is going to be empty which means that we have not assigned any values to the properties of this
object and for that reason these parentheses are empty so now let's assign the values to the properties of
this object so how can we access those properties well you simply say bank account Dot and then here you can see
many many things and among those things are the properties that we have created for example here is our owner property
so you say Bank account. owner and now you can set owner property so who will be the owner of my bank account let's
say Saina nurak that is my name okay so this is the owner of bank account and then let's say bank account dot account
number and here I will say guid do newu like this and it is going to assign find a new unique identifier to this
property which means that account number will be unique okay and then third property is bank
account. balance and here let's say for example 250 like this so with this we have
created an object of class bank account once more you first specify the name of the class and then the name of the
object and then you say that you want to create a new object which will be empty for now and then you assign the values
for the properties of that object so Bank account. owner will be Sala norak and then bank account. account number
will be new unique identifier and then bank account balance will be 250 now let's create a few more objects
of bank account class and then we will show them inside our grid so I will copy this entire code here and then paste it
and here I want to create object called bank account 2 so bank account 2. owner will be let's say Elon Musk and then
bank account to. account number will be again give me new unique identifier and then bank account 2. balance will be for
example 999 that is how much money Elon Musk has okay so this here is is second object
and then let's create one more so I will copy and paste the code and here I will change the name of the object let's call
it bank account 3 again I'm creating an empty object and then I will say bank account 3. owner will be let's say Bill
Gates and then bank account 3. account number will be new good and bank account 3. balance will be let's say
150 okay so with this we have easily created three objects of bank account class and now let's see how we can use
these objects in practice so for example let's show them inside this grid here now in order to show data inside our
grid we need to put that data inside a list and then we can simply set that list as the data source for this grid so
let's go back to the code behind press F7 and here I will create create a list of bank accounts I will call them bank
accounts and for now it is going to be new list which is empty and now what I will do is I will say Bank
accounts. add so what I will do is I will add this first bank account and then also I will add bank account two
and then bank account three like this so now that I have inside this list all of my bank accounts accounts what I can do
is I can set this list as the data source for this grid here and in order to do that and in order to work with
this Grid in our code we need to know what is its name so let's check one more time what was the name that we gave to
this grid so simply right click on the grid go to properties and find name property it should be here somewhere so
the name is bank accounts grid Okay so so now let's close this properties window and let's press F7 to go to the
code behind and here I will say bank accounts grid. data source so what I want to do
is I want to set data source for my grid and data source will be this list here which means please show this list of
bank accounts inside my grid so now when I start my application we should see these three objects inside our grid so
let's start the application and as you can see here are three objects that we have created now I know that I said that
we will not style this application and that we will focus only on writing the code but there is one thing that bothers
me a lot related to this grid and that is this empty space here so one small thing that I want to change is I want to
tell to The Columns of this grid to fill this entire space so that is one thing that I want to change so let's close our
application and let's go to this design of our form right click on the grid go to properties and here you are going to
find the property which is called let me check it is called Auto siiz columns mode that is the property that you need
and here you need to set it to fill which means that automatically the size of columns will be to fill the entire
grid so now if I start the application you will see that our grid looks much better and there is no more empty space
in our grid so in this video we learned what is object-oriented programming and how we can use it in order to build real
useful applications we also learned what are classes and what are objects and how to use them in practice in our
applications now there are still many many things that we need to add and Implement in our application but let's
do that in the next video because this video is already becoming too long on my YouTube channel you can find an entire
playlist about practical oop so practical objectoriented programming and you can watch all of the videos and
learn everything that you need about objectoriented programming and if you want to learn practical programming in
general so that you can start a career as a software developer and work on real projects in real companies then you
should join my practical programming course because there I will teach you everything that you need to know in the
shortest amount amount of time so that you can get a job as a software developer I will be there to help you in
every step of the way and your job is just to follow the plan that I have created for you so in the description I
will leave a special coupon code that you can use in order to save some money and get a discount and then if you're
not sure if this course is for you or not we have a 7-Day money back guarantee which means that if you're not satisfied
for any reason you can get all of your money back no questions asked from our side so instead of coming up with
excuses use this opportunity to finally learn programming and change your life because you really have nothing to lose
and you have a lot to gain so that would be all for this video if you have any questions you can leave those in the
comment section and please write your questions in the comment section instead of sending them directly to me in
private messages because when I reply to a public comment then all of the other people can also see that answer and they
can benefit from it and also if you enjoyed this video and if it was beneficial for you please give it a big
thumbs up so that I know and I can create more videos like this one so thank you very much for watching and I
will see you in the next video of this series which will be linked here on the screen
Define a public class named BankAccount with three properties: Owner (a string for the account holder's name), AccountNumber (a GUID to uniquely identify each account), and Balance (a decimal to track the current balance). Use { get; set; } auto-implemented properties for simplicity and readability.
A class is a blueprint or template that defines the properties and behaviors of a concept, like "Person" with attributes such as name, age, and nationality. An object is a concrete, specific instance of that class, such as "Salina, age 29, from Bosnia." The class sets the structure, while the object brings it to life with actual values.
First, install Visual Studio 2022 or later (Community edition is free) and the .NET Framework 8.0 or newer. Then, create a new C# Windows Forms App project. This provides the necessary tools and templates to design the user interface and write the code for your bank account application.
The app uses a Label for text like "Owner" and "Amount", a TextBox (named ownerTxt) to enter the account owner's name, a NumericUpDown (named amountNum) for deposit/withdraw amounts, a DataGridView (named bankAccountsGrid) to display all accounts, and three Buttons (createAccountBtn, depositBtn, withdrawBtn) to trigger actions. Each control handles a specific part of the user interface and interaction.
The app allows you to view multiple bank accounts in a grid, create new accounts by entering an owner name and generating a unique account number, deposit money into any selected account, withdraw money from any account, and see real-time balance updates in the grid. This demonstrates how OOP principles manage and manipulate real-world data.
OOP helps you model real-world entities (like a bank account) as objects with properties (owner, balance) and behaviors (deposit, withdraw). This makes code reusable, maintainable, and easier to understand because it mirrors how we think about the world. It's a fundamental approach used in modern languages like C#, Java, Python, and JavaScript.
Yes, this tutorial is designed for beginners. It starts with the core concepts of OOP (classes vs. objects) and then guides you step-by-step through setting up the project, designing the UI, and writing the code to build the complete bank account app. Even if you're new to C#, you should be able to follow along and learn by doing.
Keep this summary
Save it to LunaNotes and it becomes a real note in your library — editable, searchable, and ready to turn into flashcards or a diagram. Free to start.
Save to LunaNotesOr summarise for another video.
32K+ people have turned 65K+ videos into notes
“Very useful tool. I'm using it for the last couple weeks and I'm loving it so far. Makes learning on YouTube a great experience.”
This summary and transcript were automatically generated using AI with the Free YouTube transcript summary tool by LunaNotes.
Related summaries
Comprehensive Guide to Object-Oriented Programming (OOP) in C++
This video provides an in-depth exploration of Object-Oriented Programming (OOP) concepts in C++, covering everything from basic definitions to advanced implementations. It includes practical examples, coding demonstrations, and multiple-choice questions to reinforce understanding, making it an essential resource for students preparing for internships and placements.
Understanding My Coding Journey: From Visual Basic to Object-Oriented Programming
In this video, the speaker shares their coding journey starting from Visual Basic in high school to learning C and Object-Oriented Programming (OOP) in college. They discuss the challenges faced while transitioning to OOP concepts and how they eventually grasped the importance of messaging and encapsulation in programming.
Java Programming: A Comprehensive Guide to Understanding Java and Its Concepts
Explore Java programming concepts including OOP, exception handling, and collections. Learn how to build robust applications!
Understanding Bank Balance Sheets: A Comprehensive Guide to T-Accounts
In this video, Mr. Willis demystifies bank balance sheets, also known as T-accounts, explaining how banks manage deposits, reserves, and loans. He provides clear examples and tips to help students master the concept of fractional reserve banking and understand the relationship between assets and liabilities.
Understanding Unit 4: Files and Streams in C++
In this comprehensive video, we explore Unit 4 of the OP course, focusing on files and streams in C++. The session covers data organization, file handling, and the differences between text and binary files, along with practical coding examples.
Most viewed summaries
A Comprehensive Guide to Using Stable Diffusion Forge UI
Explore the Stable Diffusion Forge UI, customizable settings, models, and more to enhance your image generation experience.
Kolonyalismo at Imperyalismo: Ang Kasaysayan ng Pagsakop sa Pilipinas
Tuklasin ang kasaysayan ng kolonyalismo at imperyalismo sa Pilipinas sa pamamagitan ni Ferdinand Magellan.
Mastering Inpainting with Stable Diffusion: Fix Mistakes and Enhance Your Images
Learn to fix mistakes and enhance images with Stable Diffusion's inpainting features effectively.
Pamamaraan at Patakarang Kolonyal ng mga Espanyol sa Pilipinas
Tuklasin ang mga pamamaraan at patakaran ng mga Espanyol sa Pilipinas, at ang epekto nito sa mga Pilipino.
How to Install and Configure Forge: A New Stable Diffusion Web UI
Learn to install and configure the new Forge web UI for Stable Diffusion, with tips on models and settings.
Found this summary useful?
Take it with you. One click puts it in your own LunaNotes library.
Save to LunaNotes