C# Extension Methods

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

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

  • @Tharky
    @Tharky 2 года назад +50

    ✔ Very very cool
    ✔ Very easy
    ✔ Very neat

  • @SpicyMelonYT
    @SpicyMelonYT 2 года назад +44

    Every single interesting thing that I have heard about recently you make a video on like a week later. You are literally predicting what I want to learn next. Legend!

    • @Tarodev
      @Tarodev  2 года назад +35

      I'm just outside your window

    • @SpicyMelonYT
      @SpicyMelonYT 2 года назад +3

      @@Tarodev There actually was a person outside my window a few hours before I wrote that. And it wasn't my neighbors cause they are always loud and talking when they go by. Creepy bro! lol

    • @DmpDk
      @DmpDk 2 года назад +4

      @@SpicyMelonYT Ah no worries, it's normal too see programmers foraging outside in ya garden around this time of year, just give him a cuppa of joe and he will bugger of on his own. else, sprinkle your garden with invitations to sprint meetings and mails from projectmanagers / IdeaGuys with "the next big thing" to keep your garden guaranteed programmer free

    • @SpicyMelonYT
      @SpicyMelonYT 2 года назад +1

      @@DmpDk LMAO will do mate!

  • @ershadhussain8196
    @ershadhussain8196 2 года назад +38

    you are slowly becoming my favorite game dev tutorial channel. keep up the useful content!

    • @CyCloNeReactorCore
      @CyCloNeReactorCore 2 года назад +5

      hes been mine since the video about generics

    • @Tarodev
      @Tarodev  2 года назад +6

      I appreciate it :) Hopefully I can climb to #1 of your list... It is now my mission!

    • @Tarodev
      @Tarodev  2 года назад +5

      Thanks a bunch man :) Glad I can deliver enjoyable content for you

  • @Tarnil97
    @Tarnil97 2 года назад +46

    One thing I'd add is that you can use the 'ref' keyword on the extended argument. Can be useful for, for example, mutating a collection in place

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

    This was a rollercoaster of me shaking my head and nodding.
    Makes a static class called extensions, adds a method to it and calls if from the class. *face palm*
    Immediately turns the method into a proper extension method. Redeemed.
    Makes an extension method to return a random from a list of strings. *face palm*
    Immediately makes the method generic. Redeemed.
    You're a true legend.

    • @Tarodev
      @Tarodev  Год назад +1

      Gotta keep you guessing my man

  • @kubstoff1418
    @kubstoff1418 2 года назад +11

    I'm amazed by the simplicity to usefulness ratio!

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

    your channel is a goldmine for game programmers!

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

    Absolute favorite channel for intermediate level programming!

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

    ty for putting those screenshots of extension methods at the end, really neat !

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

    I just found out your channel... All I have to say: This is a goldmine!

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

    Love your little check list ♥

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

    you are my fav game dev channel plz keep making vids like this

  • @rafarodriguez4765
    @rafarodriguez4765 2 года назад +1

    After 4 years of using C# I learn something useful in each video. Thanks

  • @kyleme9697
    @kyleme9697 Год назад +1

    Time to rewrite all my code again !! That generics thing was really interesting, I need to look into that some more.

  • @ewwitsantonio
    @ewwitsantonio 2 года назад +6

    Man, I love this channel. You are creating content right in my level of skill. I can follow everything easily, but you keep on showing me things that are new/useful. Thanks for the vid!

  • @meuix3218
    @meuix3218 2 года назад +1

    bro this is INSANE !!!!!!!!!!!!!!!!!!!!!!!!!!!!

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

    I would love to see you as the game dev RUclips channel 💜 you are just awesome 🤪

  • @ivo435
    @ivo435 Год назад +2

    I am still pretty new to game development (I've been doing it for about 9 months now). This channel is absolute gold. I can't tell you how many times I have thought to myself "I wish this was a method I can call". For me, the hardest part is keeping things nice and tidy (I tend to make waaay to many scripts and I start getting lost in them). This is definitely a neat trick and I will 100% use it in the future. Thank you!

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

    You are actually someone who knows what he is talking about!
    Thanks!

  • @09mrbubbles
    @09mrbubbles 2 года назад +1

    Was about to skip this since I thought I already knew what extension methods were. Turns out I did not. It's absurd how much a ten minute video can help you in your career. Thanks a bunch!

  • @mementomori7160
    @mementomori7160 2 года назад +1

    I had no idea about this, it'll be very usefull

  • @bunggo9914
    @bunggo9914 2 года назад +1

    I always learn an entirely new thing about C# in this channel

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

    Really cool indeed ! I code in C# for 3 years now and did not know about this

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

      Programming is such a vast topic with so many concepts. You'll always discover new goodies 😊

  • @monishdhayalan2552
    @monishdhayalan2552 2 года назад +1

    i have notifications on for this channel but still no notification, i only look at it when it comes in my recommendation

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

      A few people have said this 😢

  • @fleity
    @fleity 2 года назад +6

    I noticed it in this video and a bunch of other video of you as well. Your Unity compiles and enters playmode ridiculously fast. For playmode enter I know you can disable scene and domain reload but I have run into problems with that once before. I would love a video on how to improve the speed of entering playmode (and writing your scripts in a way that works with skipping domain reload) and improving compilation speed to the level it works for you (I am already using asmdefs but even in a project with only a single script it is not as fast as yours). Thanks a bunch for the good content :).

    • @Tarodev
      @Tarodev  2 года назад +6

      This would be a few things:
      1. This is a fresh project, so not many scripts
      2. I edit a bit of the load out so you don't have to wait for it ;)

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

      @@Tarodev hehehe well okay that obviously works too :D

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

      @@fleity the hollywood style of development :D

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

      @@Tarodev big brain 🧠

  • @null21235
    @null21235 2 года назад +1

    That's so perfect for tutorial, thanks

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

    My new favorite channel

  • @Etredal
    @Etredal 2 года назад +1

    Wow I'm going to use this more!

  •  2 года назад

    Love your videos, thanks for sharing!

  • @jean-michel.houbre
    @jean-michel.houbre 2 года назад +1

    Very clear.

  • @PepijnLinden
    @PepijnLinden 2 года назад +3

    While watching this video I thought to myself: "This is neat! I should really subscribe to this guy!"
    But apparently I was already subscribed because of that amazing DOTWEEN video.
    Big thanks for spreading your knowledge and keep up the great content!

  • @JoschinoDev
    @JoschinoDev 2 года назад +3

    *this* is incredible. Time to rewrite my helper class

  • @notagamedev5494
    @notagamedev5494 2 года назад +1

    Thank you!

  • @supendi42
    @supendi42 2 года назад +1

    Of course Tarodev is inside heroes list

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

      Yeah boi 😉

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

    interesting hero gradation :D so humble that Tarodev

  • @Lukfin
    @Lukfin 2 года назад +1

    Very nice! I hope to build my toolbox of useful extension methods. Thanks for the video! Gave it a big like.

  • @TheKr0ckeR
    @TheKr0ckeR 2 года назад +3

    great guide, thanks

  • @narkid89
    @narkid89 2 года назад +1

    As always, good stuff!

  • @pliniomourao
    @pliniomourao 2 года назад +1

    Nice, simple and easy.
    Thank you for this.

  • @Димас-ТвойРазработчикИгр

    Thank you very much, your tutors are wonderful

  • @chujies
    @chujies 2 года назад +1

    Very very cool
    Very Easy
    Very Neat!
    Haha love it

  • @datablob
    @datablob 2 года назад +1

    Awesome stuff, Taro. I laughed so hard during the checklist of coolness and neatness, well done! :D

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

      I particularly also liked how you dove into multiple practical demos of the concept!

  • @Structed
    @Structed 2 года назад +1

    You should create a library with your extension methods!

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

      I've seen a few repos around with a bunch, but yeah you're right there certainly a need for an easy to install package.

  • @AlexBlackfrost
    @AlexBlackfrost 2 года назад +1

    Wow, this is great

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

    Super cool! Thanks man

  • @eduardopoffo9764
    @eduardopoffo9764 2 года назад +1

    Wonderful tutorial, had no idea this existed and now I may never stop using that hahaha
    +1 sub

  • @ardaozler631
    @ardaozler631 2 года назад +2

    Amazing tutorial as usual but can you zoom a bit when using rider so mobile users can see easier thank you ❤️

    • @Tarodev
      @Tarodev  2 года назад +1

      Ah dude in editing I remembered I didn't zoom in and felt bad. I tried to add zoom on every code segment but it looked horrible. Sorry bud >

  • @jsn4591
    @jsn4591 2 года назад +1

    Great video! To the point and a clear bunch of examples. Thanks for adding something new to my toolbox. Subbed and looking forward to checking out your other vids.

  • @lukastomasek8038
    @lukastomasek8038 2 года назад +1

    Great Tutorial as always!

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

    ✅ Very Very Cool
    ✅ Very Easy
    ✅ Very Neat

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

    this.
    this is excellent
    And so are you, my dude

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

    Thanks a lot for the video. Extension methods indeed seem Very very cool, very easy and very neat

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

    I’ve always wanted to know how to make those, great tutorial thank you

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

    This is a very old (I mean ancient) OOP trick but thanks for sharing. 😇

  • @NOOB097
    @NOOB097 2 года назад +1

    Super cool 😎

  • @Rovsau
    @Rovsau 2 года назад +1

    Hercules, Thanos, Tarodev
    I can see it now...
    public static override ThanosSnap() => DoNothing();
    Tarodev saves the world \o/

    • @Tarodev
      @Tarodev  2 года назад +1

      The power of a programmer

  • @svendpai
    @svendpai 2 года назад +1

    Another great video :) still waiting patiently for the knitting one

    • @Tarodev
      @Tarodev  2 года назад +1

      Can you handle my knitting? Not so sure

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

      Only if you can knit my handle

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

    Thanks!!!

  • @larryd9577
    @larryd9577 2 года назад +1

    Extension Methods are just syntactic sugar for grouping util functions to their according classes. Which is stupidly useful. Kotlin does it the exactly the same way, JavaScript and TypeScript has it too, just works a little different.
    I'd usually create separate classes for the extension methods named according to the class which I extend on. Like the List extensions go into ListExtensions and the Hero extensions in HeroExtensions and have them all in a name space for alle extension methods.

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

      I'm glad you don't throw every single method in a monolithic class!
      I was having a convo recently about where people store enums. Some people would chuck all enums in 1 "enums" file. I personally put them below their main class declaration.
      enum HeroType
      will be below the ScriptableHero declaration for example.

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

    Good job

  • @AetherXIV
    @AetherXIV 2 года назад +1

    NICE

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

    Awesome video as always! Just a small thing at min 6:50 you said that you are mutating a string, but that's false, you are returning a new string and printing it, the "hero" string remains the same . ("String objects are immutable: they cannot be changed after they have been created. All of the String methods and C# operators that appear to modify a string actually return the results in a new string object")

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

      I talk about string immutability in my previous video. I more meant to the context of the caller, we are 'mutating' the string. Not from a programmatic standpoint but a functional standpoint.
      It's good you mentioned it anyway as others may have the wrong idea 💡

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

    实在是太有用了!我怎么没有更早认识你呢!

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

    This is so incredibly useful.

  • @lewaplay
    @lewaplay 2 года назад +1

    Nice

  • @askcookie1
    @askcookie1 2 года назад +1

    I'd love to see a video about custom attributes. Commands from Quantum Console are good example
    [Command]
    public void Teleport(Vector3 pos)
    This would automatically grab name of method and register this as command with Vector3 argument.

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

      Didn't know Quantum Console existed until just now, pretty nice!

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

    I would be really glad a tutorial on "ref" "out" keywords

  • @adamsen2
    @adamsen2 2 года назад +1

    Hey thank you for your great videos.
    I would like to suggest a video about using events in unity, how to set them up and subscribe to them in another script.
    Best regards

  • @jsn4591
    @jsn4591 2 года назад +1

    Back again after an excursion through your channel. Awesome stuff, you're a great teacher! I hope you keep on going with more intermediate & advanced topics for us peeps who are beyond the basics. One thing I notice you do is use var instead of specifying the type when defining references, is that just a personal taste thing?

    • @Tarodev
      @Tarodev  2 года назад +1

      Personal taste, but efficiency comes into it. I can tell the type by the declaration and if I can't I'd prefer to hover to see than have every type on display.
      Sometimes you don't know the type right away, so I'd prefer to just start coding than sit there thinking about it. Curious why you prefer specifically typed?

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

      @@Tarodev thanks for your insight. I wouldn't say I prefer specifically typed, I just learned it that way. Its always seemed unnecessary to me to write the Type twice though, so the var approach is quite appealing.

    • @Tarodev
      @Tarodev  2 года назад +1

      @@jsn4591 it's the time to change! Start doing it and you will kick yourself for not doing it sooner.

  • @vishalkhombare
    @vishalkhombare 2 года назад +1

    Tarodev You are such a master!! ..What books you read? recommend to us beginners and intermediates ? Which online resource can teach us all this C# stuff like you do ? Can you recommend somethings / many things additional who really want to get good at this C# programming art. Some day please take time and make a video on this "Recommeded learning resources as per Tarodev". Thanks.

    • @Tarodev
      @Tarodev  2 года назад +1

      I didn't read any books. I learned by jumping in to make things and just looking stuff up as I got stuck. I would suggest not learning purely via unity tutorials, but focus more on pure c# content.
      Everybody learns differently, I always found hands on the best for me, but books may be best for you 😊 as long as you find the method you choose to be fun and not boring I'd say you're doing it right.

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

      @@Tarodev Yes Agreed Boss. Everyone's in that sense. Thanks a lot for your kind reply.

  • @88dejw
    @88dejw 2 года назад +1

    Great explanation! Could you please make the font a little bigger in the editor next time recording? It's a little hard to see watching this on phone

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

      Yeah sorry about that. I realize I didn't zoom when I started editing. I tried zooming the video but it looked bad 😢

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

    I did the random one before, but used IEnumerator instead of IList to make it available for other data types as well

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

      A bit more difficult with IEnumerable as it doesn't offer count. But still doable

  • @WarlikeCracker
    @WarlikeCracker 2 года назад +1

    Спасибо за годный контент

    • @Tarodev
      @Tarodev  2 года назад +1

      You're welcome :)

  • @therupoe
    @therupoe 2 года назад +2

    Hey Tarodev! Love the channel, thanks for all of the useful info.
    At the moment I'm learning c# and am just now getting into (maybe) intermediate topics (inheritance, polymorphism, structs and interfaces).
    At what point am I going to know enough to be effective in unity? I'm worried ill jump in too early, brute force stuff and learn the wrong habits. Is there like a minimum level of competency or something? I mostly understand your videos and if nothing else they give me new terms and concepts to research when I'm in over my head.

    • @Tarodev
      @Tarodev  2 года назад +2

      Interesting question. I would say learn some basic design patterns like the enum-state manager in my GameManager video and then also a normal state manager (infallible code has a good one). If you're making a smallish game, stick with the enum game manager in my opinion.
      With that knowledge I think you're good to just jump in. Making mistakes is learning. You can always join my discord to ask me/community questions if you're unsure about something

    • @therupoe
      @therupoe 2 года назад +1

      @@Tarodev thanks, man! I appreciate you taking the time.

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

    Gold

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

    Great video.
    A little concerned about what's considered a hero though.
    *stares at Thanos' name

  • @ericbeaulieu419
    @ericbeaulieu419 2 года назад +1

    Unity knows that Thanos isn't a hero

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

      It seemed that way... We know he is though

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

    Something could be good is a video about namespaces. I take some 3rd parties scripts and almost no one uses. So, how to use and about how struct them in directories could be a good video =) (Sorry about my english)

  • @TheElvinGamer
    @TheElvinGamer 2 года назад +1

    I am a C# dev but I clicked purely because of the Clash of Clans font so take that for what you will

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

      I love it 😅

  • @homemacai
    @homemacai 2 года назад +1

    it's 420 O' Clock in classroom 69 kids!

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

    420 69 lol
    This legend sneaked in these holy numbers in a programming tutorial. Niceee XD

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

      Excuse me they were entirely random

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

    I have a question .. sometimes when I work with static classes in some mobile devices they doesn't work for some reason .. some said they get garbage collected , is there a way to protect a class from getting garbage collected or is there something I don't know about ?

  • @bambuccigames
    @bambuccigames 2 года назад +3

    How come you enter Play Mode so fast?

    • @ardaozler631
      @ardaozler631 2 года назад +1

      He has a tutorial on that

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

      Here it is: ruclips.net/video/P7cYVg5fAvY/видео.html
      Also, ctrl + p is the hotkey to enter

  • @youcancallmedoggie
    @youcancallmedoggie 2 года назад +2

    ENGAGING

  • @znimator
    @znimator 2 года назад +1

    Why his Unity loading so fast i cant understand bruh
    my takes like 20 seconds to load stuff and then run game

    • @Tarodev
      @Tarodev  2 года назад +1

      Check out this tutorial my guy ruclips.net/video/P7cYVg5fAvY/видео.html

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

    What code editor are you using VS Code?

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

    5:38 lmao

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

    whats with the rider licences?

  • @hryhoriinevmerzhytskyi4299
    @hryhoriinevmerzhytskyi4299 10 месяцев назад

    Random int 420 😂 Ok, like ✊

  • @didntask2438
    @didntask2438 2 года назад +1

    Hello

  • @YOSFP
    @YOSFP 2 года назад +1

    how does your project start so fast lol

    • @Tarodev
      @Tarodev  2 года назад +1

      Go to my channel and look for 'enter play mode faster'

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

      @@Tarodev I had a feeling you had one video about that, thanks :)

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

    Good video, really helpful. But unfortunately have to dislike and report because typing braces in the same line is war crime.

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

      Haha getouttahereeeeee

  • @ГеймДеб
    @ГеймДеб 2 года назад

    666th like

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

    public static void DestroyChildrenRecursive(this Transform transform)
    {
    foreach (Transform t in transform)
    {
    t.DestroyChildrenRecursive();
    }
    Object.Destroy(transform.gameObject);
    }

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

    Old video, but why do you have a flat extension method? Vector3.ProjectOnPlane() already does exactly what that does if you use Vector3.up as the second argument. To be fair, I do wish project on plane were an extension method by default.

  • @WolfCanine-u5w
    @WolfCanine-u5w Год назад

    I Made tihs one =>
    public static T GetRandom(this List ts, int initialInclusive = 0, int finalExclusive = 0)
    {
    if (finalExclusive == 0) { finalExclusive = ts.Count; }
    return ts[UnityEngine.Random.Range(initialInclusive, finalExclusive)];
    }