C-SHARP - 3.2 Object and class
Hello everyone and welcome to this new video. In this video, we will discuss the concept of objects. The C# language is a programming language that is part of the so-called Object-Oriented languages, they are also called OOP which is a shortcut for Object-Oriented Programming. You should know that in C#, all we will use is an object. And in this video, we are going to be interested in creating our own objects. To create an object in C#, you must first define what it will look like. For that, we will use classes, the principle is quite simple, we will define them only once with different parameters and we can call them several times with parameters whose values will be different. Classes will allow us to define what our object should look like. Once we have created this mold, we can create as many objects as we wish with somewhat different properties. We will take an example to have something a little more concrete. Let's imagine that we are the owner of a car garage. In our case, we are therefore going to manage cars, the cars have common characteristics on the other hand which can have different values. All cars have a color but this color can be different for each car, but also all cars have doors but depending on the car the number of doors can vary 3, 5 etc. When we create a class for our car, we will define what are called attributes. In the context of a car, we will define a brand attribute, a year attribute and a color attribute, for example. From this class, we will be able to create different objects called instances. Each instance will have the same attributes, on the other hand the values of the attributes of the instances will be different, for example here we have a car of the Peugeot brand of the year 2019 and of a blue color, here a Mercedes car of the year 2021 and a gray color etc. But also, in our objects we can create functions that will allow us to act on our instances, a function that belongs to a class is what we call methods. In the case of our car, we can create methods such as starting, advancing, or reversing. If you n' you're still not sure you understand what object-oriented programming can be used for beyond creating cars or anything else. Well, object-oriented programming will first of all help us to better organize our code and avoid repeating lines and lines of code. As I told you in a previous video, our goal as a developer is to create programs that can be reused and object-oriented programming will allow us to meet this goal. So rather than write an almost identical block of code 50 times to create a multitude of cars, especially if you are a garage for example, we will be able to create a unique class which will then allow us in a single line of code to create a car with a multitude of different attributes. So that's it for object programming and classes. Now let's go to Visual Studio and see how to create a class in C#. we will be able to create a unique class which will allow us later in a single line of code to create a car with a multitude of different attributes. So that's it for object programming and classes. Now let's go to Visual Studio and see how to create a class in C#. we will be able to create a unique class which will allow us later in a single line of code to create a car with a multitude of different attributes. So that's it for object programming and classes. Now let's go to Visual Studio and see how to create a class in C#.