Introduction
It is important for a developer to understand the concepts of OOPS or any programming language concepts through real-world examples.
Starting in C#, the first thing which comes into the picture is objects and classes.
Class
A class is a data type that defines a collection of methods and properties in a unit. A class contains one or more objects (I will explain object in the next point, just remember object is described by the class which acts as an instance) which does not change during the execution of a program.
Real-World Example
Class acts like a blueprint. We have a blueprint of a house through which we can make many houses which will have the same properties and methods (operations). Through that blueprint, we can make a house of Mr. Aditya and through that blueprint, we can make a house of Mr. Amatya.
Object
An object is an instance of a class. There can be more than one instances of a class and they contain their own data.
Real-World Example
Here, the houses of Mr. Amatya and Mr. Aditya can be treated as objects of class House.
- Blueprint of House - Class
- House of Mr. Amatya - Object
Array and List
An array has a fixed size with continuous memory allocation of the same datatype. An array index starts at zero.
Declaring array - datatype[] arrayName;
Real-World Example
If Mr. Shryansh uses debit cards, therefore, he will purchase a wallet which has 2-3 slots where he can keep his cards.
He will place his cards in a continuous way so it will be easy and effective. Through this example, you can remember this concept.
Now, say after a few years, he got 4 debit cards and he is having three slots to keep his cards, now his wallet will not be able to keep the cards in an effective way. He will have to purchase a new wallet which should have at least 4 slots for keeping the cards. Though this scenario, you can get the demerits of Array.
Whereas list is a generic type which provides most of the collection's related built-in methods and properties including add, remove, search, and sort.
Example - List<int> numbers = new List<int>();
Real-World Example
Suppose you are in a general store, but you don't know what items to buy. By seeing the offers and requirements you can buy 10 items or even 20 items. Here List comes into the picture. Your items are not fixed and you are adding the items based on your requirements, deals, and offers. After picking 20 items from the store, you calculated the price and it exceeds from 1000 (as you brought only 1000 rupees), so you want to remove some items which are not important or you want it after some days.
So you removed 5 items and the bill was in your budget (say it becomes 900rs). In this scenorio, you can remember the concept of Lists. (Some will be confused with datatypes as List has same datatypes for its items, so say here all the items which I have taken is in String dataType)

Join the conversation! Your thoughts help the community grow.