C# constructors 👷

Поділитися
Вставка
  • Опубліковано 4 січ 2025

КОМЕНТАРІ • 81

  • @BroCodez
    @BroCodez  3 роки тому +32

    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 5 місяців тому +1

      Can you change the constructor parameter names so that they don't match the parameters at the top?

  • @atdawntime
    @atdawntime 2 роки тому +88

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

  • @JULIANTOUCH
    @JULIANTOUCH 2 роки тому +17

    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 Рік тому +4

    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 2 роки тому +8

    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 роки тому +5

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

  • @omarjahanzaib6889
    @omarjahanzaib6889 2 роки тому +2

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

  • @MagicCubeWorld
    @MagicCubeWorld 2 місяці тому

    Simply awesome. You're very good at this. Thank you. I watched the video once and I totally get it and ready to use it in my game.

  • @pramodhananth5591
    @pramodhananth5591 3 роки тому +24

    85 views only! your supremely underrated

  • @astrometries1944
    @astrometries1944 8 місяців тому

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

  • @JoseBenavides456
    @JoseBenavides456 Рік тому

    Great delivery of the information! Really helps!

  • @hjoseph777
    @hjoseph777 7 місяців тому

    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#

  • @tessy5386
    @tessy5386 3 місяці тому

    I struggle so much with my Codeacademy tutorials. You help me out. Beciming a bro soon

  • @hardyhusen1480
    @hardyhusen1480 6 місяців тому

    its so good and clear explain only five minutes

  • @Fibr3Optix
    @Fibr3Optix 2 роки тому +1

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

  • @torquuato
    @torquuato 6 місяців тому

    good video.

  • @massimochiapelli3366
    @massimochiapelli3366 9 місяців тому

    Great!!!✌

  • @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!

  • @McPatoo
    @McPatoo Рік тому

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

  • @mmaranta785
    @mmaranta785 3 місяці тому

    Great!

  • @gabrielduque6086
    @gabrielduque6086 6 місяців тому

    Easy and simple

  • @mouinmakary
    @mouinmakary 2 роки тому +1

    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.

  • @elbekrakhimov2757
    @elbekrakhimov2757 2 роки тому +1

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

  • @ramanavenkat715
    @ramanavenkat715 Рік тому

    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.

  • @EnglishVocabularyBooster
    @EnglishVocabularyBooster Рік тому

    Wow!

  • @torremocha2974
    @torremocha2974 4 місяці тому +1

    Bro I finally understand 🙏🙏🙏

  • @maxxlazos1884
    @maxxlazos1884 Рік тому

    "hey dad, why did you name me Bro Code"
    -my future daughter

  • @pxckbl6883
    @pxckbl6883 Рік тому

    👌👌

  • @lukesage9487
    @lukesage9487 Рік тому

    You're actually the goat

  • @spartanranger
    @spartanranger 3 роки тому

    Thanks for the video Bro.

  • @triton5457
    @triton5457 2 роки тому

    great vid👍🏻

  • @oheil5694
    @oheil5694 2 роки тому

    God Job

  • @kenlee1159
    @kenlee1159 2 роки тому

    I love cars that makes vroom vroom sound

  • @LucParent905
    @LucParent905 3 роки тому

    Merci M. Bro

  • @LeadHoodCode
    @LeadHoodCode Рік тому +2

    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?

  • @myheroskryptonite
    @myheroskryptonite 11 місяців тому

    thank you

  • @visualfinesse7445
    @visualfinesse7445 3 місяці тому

    The Time to Subscribe, TTS, is under 45 seconds.
    Legend.

  • @jt.633
    @jt.633 Рік тому

    thank you so much

  • @jakoblambert2803
    @jakoblambert2803 Місяць тому

  • @yashwantchoure
    @yashwantchoure Рік тому

    If it has all four tires and gets you from point A to point B then it's a car" - Takumi Fujiwara

  • @talivoszn
    @talivoszn Місяць тому

    Pew pew pow

  • @SweetPeachannel
    @SweetPeachannel 2 роки тому

    thx Bro ...

  • @budderrar5751
    @budderrar5751 2 роки тому

    noice

  •  3 роки тому

    Thanks Bro!

  • @clarkzombergaming8456
    @clarkzombergaming8456 2 роки тому +1

    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✌

  • @christophbruns8127
    @christophbruns8127 3 роки тому

    Großartig!!

  • @fmiimf2294
    @fmiimf2294 2 роки тому

    for Car, why the year is not passed on the Drive method? Nor the color

  • @edward7786
    @edward7786 2 роки тому

    TY

  • @axlecode8598
    @axlecode8598 2 роки тому

    👍

  • @matherov
    @matherov 9 місяців тому +1

    Watching in 2024

  • @ciyezyosiatabwa3266
    @ciyezyosiatabwa3266 3 роки тому

    Sir your voice is very clear but the screen is not clear

  • @hingsing1
    @hingsing1 7 місяців тому

    How come you named the constructor also Human (same name as the class 'Human' declaration)? Is that a requirement or just convention

  • @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

  • @RealRower1
    @RealRower1 Рік тому

    is it me or when you say like in the video the like and dislike button around it glows

  • @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.

  • @whitedinamo
    @whitedinamo 2 роки тому

    lesson check😇

  • @Luka_WiFi
    @Luka_WiFi Рік тому

    no need of this keyword in class constructor. Do we?

  • @its_chaudev
    @its_chaudev 2 місяці тому

    random comment🎉

  • @xoomzera2830
    @xoomzera2830 2 роки тому

    u forgot to add the year xD

  • @fortfanop
    @fortfanop 3 роки тому

    first

  • @dev0_018
    @dev0_018 2 роки тому

    🤣🤣🤣🤣🤣🤣

  • @michaeldemontagne7366
    @michaeldemontagne7366 8 місяців тому

    brother, this is too complicated I dumb asf

  • @the_dude_josh
    @the_dude_josh Рік тому

    Random comment down below

  • @definitelynotchris4776
    @definitelynotchris4776 3 місяці тому

    81k is still too little

  • @JohnRafferty-v8v
    @JohnRafferty-v8v Рік тому

    random comment.

  • @arshiaa104
    @arshiaa104 Рік тому

    Comment

  • @c.Orange
    @c.Orange Рік тому

    random comment

  • @jointherevolution5577
    @jointherevolution5577 2 роки тому

    Random

  • @engirckt5410
    @engirckt5410 3 роки тому

    second lol

  • @Frigol33tGaming
    @Frigol33tGaming 11 місяців тому

    random comment

  • @sapoman01
    @sapoman01 3 місяці тому

    Random

  • @Musicalcode313
    @Musicalcode313 5 місяців тому

    random comment