C# constructors tutorial example explained #C# #constuctor #tutorial using System; namespace MyFirstProgram { class Program …
24 Comments
Leave a Reply
You must be logged in to post a comment.
C# constructors tutorial example explained #C# #constuctor #tutorial using System; namespace MyFirstProgram { class Program …
You must be logged in to post a comment.
using System;
namespace MyFirstProgram
{
class Program
{
static void Main(string[] args)
{
// constructor = A special method in a class
// Same name as the class name
// Can be used to assign arguments to fields when creating an object
Car car1 = new Car("Ford", "Mustang", 2022, "red");
Car car2 = new Car("Chevy", "Corvette", 2021, "blue");
car1.Drive();
car2.Drive();
Console.ReadKey();
}
}
class Car
{
String make;
String model;
int year;
String color;
public Car(String make, String model, int year, String color)
{
this.make = make;
this.model = model;
this.year = year;
this.color = color;
}
public void Drive()
{
Console.WriteLine("You drive the " + make + " " + model);
}
}
}
Hey Bro Code, please, keep doing this type of videos: Short, concise and straight to the point. Those are good for the ones that already have some knowledge and just want a refresher or do not like to wait a lot. I love it! Thanks!
giving fast, effective lessons, and even leaves the code in comments
Truly a gigachad
great video👍. P.S. try to differentiate the names of declared variables and parameters of the constructor.
Like, "int year;" and "public Car(int aYear/carYear…) {}"
TY
thx Bro …
why did you the same thing 2 times, only with different names.
We got it in the first example already.
good one
I love cars that makes vroom vroom sound
great vid👍🏻
God Job
for Car, why the year is not passed on the Drive method? Nor the color
Random comment.// Great clear series, very informational.
your examples are very simple and unique,
but can you make a similar video with : an array of cars, private model – year … , and using the constructor.
the car example was exactly the explanation I was looking for. Thanks
lesson check😇
Großartig!!
Thank you for this course it's helping me a lot
Sir your voice is very clear but the screen is not clear
Merci M. Bro
Thanks for the video Bro.
Thanks Bro!
85 views only! your supremely underrated
second lol
first