C# constructors 👷

preview_player
Показать описание
C# constructors tutorial example explained

#C# #constuctor #tutorial

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)
{
}

public void Drive()
{
Console.WriteLine("You drive the " + make + " " + model);
}
}
}
Рекомендации по теме
Комментарии
Автор

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);
}
}
}

BroCodez
Автор

giving fast, effective lessons, and even leaves the code in comments
Truly a gigachad

atdawntime
Автор

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!

JULIANTOUCH
Автор

Bro you are by far the best at explaining basic concepts on youtube for C# that I've watched. Everyone else bombarders beginners with jargon and is way less concise. Keep up the great work!

amrsadek
Автор

You can really tell the effort put into a tutorial when it’s concise, easy to follow, and informative at the same time. Shits not easy. Good job

dactorwatson
Автор

the car example was exactly the explanation I was looking for. Thanks

bioblade
Автор

85 views only! your supremely underrated

pramodhananth
Автор

I am new to programming, and your videos are the best as they are short, concise and use analogies. Keep up the good work.

omarjahanzaib
Автор

Really appreciate your stuff, man! Saving my ass this finals season. Love what you do, keep keeping young people in coding.

astrometries
Автор

its so good and clear explain only five minutes

hardyhusen
Автор

Bro, I really like your video. It is short, concise, and to the point. I wish you could make a series like that for C#

hjoseph
Автор

Thank you! You helped me so much with studying c#, your channel is amazing! Also, your voice is so similar to Ryukahr's voice it's crazy!

atsu
Автор

Random comment.// Great clear series, very informational.

FibrOptix
Автор

Great delivery of the information! Really helps!

JoseBenavides
Автор

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.

mouinmakary
Автор

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...) {}"

elbekrakhimov
Автор

In Visual Studio you can use "ctor" and double tab then it will create constructor for you. Make sure the cursor inside the class. Reply if it works. Idk about versions. It's working in VS 2019.

ramanavenkat
Автор

Gigachad bro thx :))) sometimes i forget this little things xdxd and then ur videos can save me from troubles

McPatoo
Автор

"hey dad, why did you name me Bro Code"

-my future daughter

maxxlazos
Автор

I love cars that makes vroom vroom sound

kenlee