C# constructors 👷

Поделиться
HTML-код
  • Опубликовано: 5 янв 2025

Комментарии •

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

  • @mmaranta785
    @mmaranta785 3 месяца назад

    Great!

  • @McPatoo
    @McPatoo Год назад

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

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

  • @maxxlazos1884
    @maxxlazos1884 Год назад

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

  • @pxckbl6883
    @pxckbl6883 Год назад

    👌👌

  • @torremocha2974
    @torremocha2974 4 месяца назад +1

    Bro I finally understand 🙏🙏🙏

  • @spartanranger
    @spartanranger 3 года назад

    Thanks for the video Bro.

  • @lukesage9487
    @lukesage9487 Год назад

    You're actually the goat

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

  • @fmiimf2294
    @fmiimf2294 2 года назад

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

  • @edward7786
    @edward7786 2 года назад

    TY

  • @christophbruns8127
    @christophbruns8127 3 года назад

    Großartig!!

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

  • @definitelynotchris4776
    @definitelynotchris4776 3 месяца назад

    81k is still too little

  • @the_dude_josh
    @the_dude_josh Год назад

    Random comment down below

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