C# constructors 👷

  Рет қаралды 82,811

Bro Code

Bro Code

Күн бұрын

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)
{
this.make = make;
this.model = model;
this.year = year;
this.color = color;
}
public void Drive()
{
Console.WriteLine("You drive the " + make + " " + model);
}
}
}

Пікірлер: 77
@BroCodez
@BroCodez 3 жыл бұрын
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); } } }
@7415_Gamer
@7415_Gamer 2 ай бұрын
Can you change the constructor parameter names so that they don't match the parameters at the top?
@atdawntime
@atdawntime 2 жыл бұрын
giving fast, effective lessons, and even leaves the code in comments Truly a gigachad
@enespinar9711
@enespinar9711 11 ай бұрын
Bro is defining of Gigachad
@JULIANTOUCH
@JULIANTOUCH 2 жыл бұрын
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!
@dactorwatson4313
@dactorwatson4313 Жыл бұрын
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
@amrsadek5853
@amrsadek5853 Жыл бұрын
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!
@bioblade87
@bioblade87 2 жыл бұрын
the car example was exactly the explanation I was looking for. Thanks
@omarjahanzaib6889
@omarjahanzaib6889 Жыл бұрын
I am new to programming, and your videos are the best as they are short, concise and use analogies. Keep up the good work.
@pramodhananth5591
@pramodhananth5591 3 жыл бұрын
85 views only! your supremely underrated
@sjondepon874
@sjondepon874 Жыл бұрын
Not anymore 😊
@patelvraj1362
@patelvraj1362 11 ай бұрын
Now it's increased
@Sacrifizer_Official
@Sacrifizer_Official 10 ай бұрын
55k now
@user-zt7ke4ql8h
@user-zt7ke4ql8h 7 ай бұрын
His channel has grown so much
@mdadol6802
@mdadol6802 Ай бұрын
77k now💀💀
@hjoseph777
@hjoseph777 4 ай бұрын
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#
@astrometries1944
@astrometries1944 5 ай бұрын
Really appreciate your stuff, man! Saving my ass this finals season. Love what you do, keep keeping young people in coding.
@tessy5386
@tessy5386 19 күн бұрын
I struggle so much with my Codeacademy tutorials. You help me out. Beciming a bro soon
@mouinmakary
@mouinmakary 2 жыл бұрын
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.
@atsu0002
@atsu0002 Жыл бұрын
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!
@JoseBenavides456
@JoseBenavides456 Жыл бұрын
Great delivery of the information! Really helps!
@hardyhusen1480
@hardyhusen1480 3 ай бұрын
its so good and clear explain only five minutes
@elbekrakhimov2757
@elbekrakhimov2757 2 жыл бұрын
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...) {}"
@Fibr3Optix
@Fibr3Optix 2 жыл бұрын
Random comment.// Great clear series, very informational.
@ramanavenkat715
@ramanavenkat715 10 ай бұрын
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.
@McPatoo
@McPatoo 11 ай бұрын
Gigachad bro thx :))) sometimes i forget this little things xdxd and then ur videos can save me from troubles
@kenlee1159
@kenlee1159 2 жыл бұрын
I love cars that makes vroom vroom sound
@maxxlazos1884
@maxxlazos1884 11 ай бұрын
"hey dad, why did you name me Bro Code" -my future daughter
@LeadHoodCode
@LeadHoodCode Жыл бұрын
Why are you using a capital S instead of s when writing string. Is there any difference? And why do you then use lowered case i for int instead of Int?
@torquuato
@torquuato 3 ай бұрын
good video.
@mmaranta785
@mmaranta785 27 күн бұрын
Great!
@visualfinesse7445
@visualfinesse7445 8 күн бұрын
The Time to Subscribe, TTS, is under 45 seconds. Legend.
@gabrielduque6086
@gabrielduque6086 3 ай бұрын
Easy and simple
@yashwantchoure
@yashwantchoure Жыл бұрын
If it has all four tires and gets you from point A to point B then it's a car" - Takumi Fujiwara
@torremocha2974
@torremocha2974 Ай бұрын
Bro I finally understand 🙏🙏🙏
@massimochiapelli3366
@massimochiapelli3366 6 ай бұрын
Great!!!✌
@lukesage9487
@lukesage9487 Жыл бұрын
You're actually the goat
@hingsing1
@hingsing1 4 ай бұрын
How come you named the constructor also Human (same name as the class 'Human' declaration)? Is that a requirement or just convention
@pxckbl6883
@pxckbl6883 9 ай бұрын
👌👌
@EnglishVocabularyBooster
@EnglishVocabularyBooster Жыл бұрын
Wow!
@fmiimf2294
@fmiimf2294 2 жыл бұрын
for Car, why the year is not passed on the Drive method? Nor the color
@spartanranger
@spartanranger 3 жыл бұрын
Thanks for the video Bro.
@clarkzombergaming8456
@clarkzombergaming8456 Жыл бұрын
hi bro . umm just to let you know i dont know which language version your using but yeah i type the same code you show in your videos, for you ,you have no errors but i am running into many errors like object refrence is required for non static bla blah. btw i use vs code 2022..... please reply✌
@myheroskryptonite
@myheroskryptonite 8 ай бұрын
thank you
@jt.633
@jt.633 Жыл бұрын
thank you so much
@triton5457
@triton5457 2 жыл бұрын
great vid👍🏻
@LucParent905
@LucParent905 3 жыл бұрын
Merci M. Bro
@SweetPeachannel
@SweetPeachannel 2 жыл бұрын
thx Bro ...
@christophbruns8127
@christophbruns8127 2 жыл бұрын
Großartig!!
@oheil5694
@oheil5694 2 жыл бұрын
God Job
3 жыл бұрын
Thanks Bro!
@budderrar5751
@budderrar5751 Жыл бұрын
noice
@axlecode8598
@axlecode8598 2 жыл бұрын
👍
@edward7786
@edward7786 2 жыл бұрын
TY
@xr_xharprazoraxtra5428
@xr_xharprazoraxtra5428 Жыл бұрын
Question : How to have default parameters and optional parameters ? for example : using the Car Class Make : default = "Bro", Model : default = "Punk" Year : default = 2048 Color : default = "black" then in the main I have : Car car3 = new Car(,"Woohoo",2023,) //expecting to have a Bro Woohoo which is made in 2023 and it's black ?
@therealeli800
@therealeli800 Жыл бұрын
I think its the same concept to add default values to a variable, instead of String make; you would change this to “String make = “default;” that way if a field is left unassigned the program will automatically assign it that default value.
@ciyezyosiatabwa3266
@ciyezyosiatabwa3266 3 жыл бұрын
Sir your voice is very clear but the screen is not clear
@iamkingmatt2260
@iamkingmatt2260 6 ай бұрын
Watching in 2024
@RealRower1
@RealRower1 11 ай бұрын
is it me or when you say like in the video the like and dislike button around it glows
@stewiegriffin6503
@stewiegriffin6503 2 жыл бұрын
why did you the same thing 2 times, only with different names. We got it in the first example already. good one
@Luka_WiFi
@Luka_WiFi Жыл бұрын
no need of this keyword in class constructor. Do we?
@whitedinamo
@whitedinamo 2 жыл бұрын
lesson check😇
@fortfanop
@fortfanop 3 жыл бұрын
first
@xoomzera2830
@xoomzera2830 Жыл бұрын
u forgot to add the year xD
@the_dude_josh
@the_dude_josh 9 ай бұрын
Random comment down below
@arshiaa104
@arshiaa104 Жыл бұрын
Comment
@michaeldemontagne7366
@michaeldemontagne7366 5 ай бұрын
brother, this is too complicated I dumb asf
@dev0_018
@dev0_018 Жыл бұрын
🤣🤣🤣🤣🤣🤣
@definitelynotchris4776
@definitelynotchris4776 10 күн бұрын
81k is still too little
@JohnRafferty-v8v
@JohnRafferty-v8v Жыл бұрын
random comment.
@Musicalcode313
@Musicalcode313 2 ай бұрын
random comment
@sapoman01
@sapoman01 14 күн бұрын
Random
@engirckt5410
@engirckt5410 3 жыл бұрын
second lol
@Frigol33tGaming
@Frigol33tGaming 8 ай бұрын
random comment
@jointherevolution5577
@jointherevolution5577 2 жыл бұрын
Random
@c.Orange
@c.Orange Жыл бұрын
random comment
C# static 🚫
5:03
Bro Code
Рет қаралды 73 М.
C# polymorphism 🎭
5:11
Bro Code
Рет қаралды 82 М.
Миллионер | 2 серия
16:04
Million Show
Рет қаралды 567 М.
Миллионер | 1 - серия
34:31
Million Show
Рет қаралды 2,5 МЛН
1 сквиш тебе или 2 другому? 😌 #шортс #виола
00:36
Constructors | C# | Tutorial 26
10:29
Giraffe Academy
Рет қаралды 87 М.
My 10 “Clean” Code Principles (Start These Now)
15:12
Conner Ardman
Рет қаралды 242 М.
C# Constructors - This is how to use them, and WHY
8:00
tutorialsEU - C#
Рет қаралды 7 М.
C# methods 📞
6:05
Bro Code
Рет қаралды 56 М.
Learning C# In A Week... Otherwise I Fail University
9:04
C# Constructors Tutorial | Mosh
23:24
Programming with Mosh
Рет қаралды 236 М.
C# objects 🧍‍♂️
5:01
Bro Code
Рет қаралды 48 М.
WHY IS THE STACK SO FAST?
13:46
Core Dumped
Рет қаралды 159 М.
Naming Things in Code
7:25
CodeAesthetic
Рет қаралды 2,2 МЛН
Миллионер | 2 серия
16:04
Million Show
Рет қаралды 567 М.