C# Generics - The complete guide

Поділитися
Вставка
  • Опубліковано 22 лис 2024

КОМЕНТАРІ • 136

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

    It was explained very well, thank you. Also, it looks like c# attributes are poorly covered on UA-cam, please can you make a tutorial about them? 🙂

  • @DanPos
    @DanPos 3 роки тому +18

    I'd been looking to do some more research into generics so this hit at the right time mate! Also, sick thumbnail

    • @Tarodev
      @Tarodev  3 роки тому +3

      A man who appreciates the art of thumbnails ❤

  • @RAPHAELSC
    @RAPHAELSC Рік тому +1

    I am very impressed!!!! How you teach complex topic that even a begginner would understand and a pro would finally comprehend!

  • @TNothingFree
    @TNothingFree 3 роки тому +2

    Great tutorial for beginners!.
    It misses few concepts that are important to talk about when teaching generics:
    - What is the difference between T and object - Why not use ArrayList?
    - What is a generic type T - How it's essentially different than a regular class type (Like array of objects?)
    This is a good point to talk about meta-programming, How a generic type looks under the hood.
    - covariance and contravariance in generic programming.
    A good place to look at will be Clr via C#, explains very well what is a type and a generic type.

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

    This is the topic where I learnt in school and forget thinking I may not need it.
    However it does fit in the need of fundamentals

  • @gaelp.5847
    @gaelp.5847 3 місяці тому

    Aside from the factory, the examples provided do not display re-usability as explained since re-usability is already provided by the Hero generic class inheritance or the ping interface.
    You can just have a HeroHelper with a non-generic Hero data type and it will do exactly the same but your code will even be clearer..
    Generics really shine when you need to handle elements of various types all together or when you want to define behaviors that do not depend on the type. So if you use where T:WhateverType and define behaviors based on WhateverType, it's fine but you do not need generics.
    Example : You have a generic class Selection handling player's selection of an item. This Selection does require a type T since it will trigger an event with its T data upon selection (since you need to now who fired the event).
    Now let's say i want that behavior on an Item & on a button : Just declare UIItem : Selection & UIButton : Selection and hook up its selection event and that's it.
    (and this is an inheritance example but it works just the same by composition).

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

    For so long I've been looking at generics and failing to understand how and when to use it. I always had a feeling that I needed to use (or would be useful) but never could figure it out. You've explained it so simply that it just makes perfect sense to me now. Thank you! :)

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

    Great explanation, thank you, I've stumbled upon some videos about generic functions, and the guys keep theoreticising about generics without explaining it deeply in this manner

  • @techoutlook9235
    @techoutlook9235 Рік тому +1

    This is the explanation I am looking for. Thank you so much.

  • @maciejp8001
    @maciejp8001 Рік тому +1

    Big thanks. Never before did I understood those as well!

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

    Great video! one point i would have added is how generics work with inheritance. So you could also make a class WarriorHelper : HeroHelper if you wanted to add a function that is specific to warriors.
    This is also valuable for working with generics in monobehaviours in unity, as you dont create monobehaviours by their constructor and cant add a monobehaviour with a generic type as component.

  • @Briezar
    @Briezar 3 роки тому +12

    just found out about your channel from a certain video that has absolute random numbers as examples and I must say I'm really digging into your clean video format, deep explanation and occasional dad jokes. Subbed and will hope for the channel to blow up soon.

    • @Tarodev
      @Tarodev  3 роки тому +3

      Pure random numbers ;)

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

    Just wow. TY I like the explanation. You have made my day! I can't explain how this makes me so happy! I was looking for an explanation of this for while. It is explained so well and I can immediately apply it.

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

      That's what I like to hear 😊

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

    Eggcellent video, quite informative. If you may, could you drop the bgm in future videos, or try with a less intrusive theme? It gets quite annoying after a while when using headphones, thank you.

  • @Vastlee
    @Vastlee 3 роки тому +2

    Look at you Mr. Fancy Pants with your C# 10 & VS 2022. I can't wait until Unity catches up some. Of all the new features, I oddly think the file-scoped namespace is going to be my favorite. Tabbing an entire class for nothing more than a namespace makes my OCD tingle.

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

      I especially like it for videos as it keeps boilerplate away and allows people to focus purely on the content. This is magnified for new devs who have only experienced unity and never created a console app, static void main could be confusing.

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

    i was going over few Tutorial in generic and depress a bit.. this one click me :) right explanation :)

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

    I've smashed that like. You were extremely helpful in assisting to understand Generics and also many other topics which you've shown unknowingly. 😊

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

      Thanks for the like buddy 🙏

  • @geniusforever5780
    @geniusforever5780 3 роки тому +3

    Hey! I recently found your channel and must say this channel is blessing. Also your art style is fooking awesome, it would be a another blessing if you do that kind of art tutorials

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

      I'm honoured you would like me to do an art video, but I absolutely feel like an imposter in the art world. Are you talking about all the little mascots I drew?

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

    fantastic and straight-forward explanation. thanks man :)

  • @andradiusvolatius
    @andradiusvolatius 3 роки тому +3

    your videos are very good, they are helping me a lot in the creation processor of my game.
    I spent 1 year studying to be able to make a game, now with some of your videos I managed to progress much faster.
    if I made a video showing my project would you see? I'm sure you'll be surprised by my idea.

    • @Tarodev
      @Tarodev  3 роки тому +1

      These are the comments which make me feel good about what I'm doing. Yes I'd love to see your work

  • @tommywilkinson33
    @tommywilkinson33 Рік тому +3

    I wish I could double thumbs up this. I’ve read through the definition of generics and interfaces. I’ve written them out in my own code. But I never fully understood them until seeing the examples you had here. This explained so many of the things I haven’t quite mastered in C#. I feel so much more powerful now! But seriously thank you for this!

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

    Best Tutorials on the net xD

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

    Thank you so much for sharing this, it's clear as, I will try to implemented in a more practical way to review the concept~cheers~

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

    Really enjoyed. Would love to jump into game programming.

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

      We'd love to have you 😊

  • @billyfrcs08
    @billyfrcs08 3 роки тому +2

    Thanks!

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

    Phenomenal video, keep up the great work man!!

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

    Can you please do a playlist focused on core C#? It'd be so helpful

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

    Great stuff! You taught me so much in very little time! Thank you.

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

    Dude, thank you! Well put and understandable.

  • @basicdogtrainings9389
    @basicdogtrainings9389 3 роки тому +1

    Thanks Taro, for C# Generics today I learned more from you👏[Battle King

  • @archastudio2676
    @archastudio2676 3 роки тому +1

    I love your videos, i know much of the stuff in it but the small details and tips you add make them very cool. thanks for sharing your knowledge :D

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

      Glad you like them!

  • @Shahmuradov
    @Shahmuradov 3 роки тому +6

    Put baby in me
    - Anything

  • @Siberdt
    @Siberdt 3 роки тому +1

    Why you are using
    void PingMap(T inputObject) where T : IPing{}
    if you can use the way w/o generics
    void PingMap(IPing inputObject){}
    ?

  • @DJnoratos
    @DJnoratos 3 роки тому +1

    Great tutorial, thanks for good explanation

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

    Can you make a video about Quaternions and Rotation?

  • @svendpai
    @svendpai 3 роки тому +1

    Everything about this is so great, really nice and relevant topics!

    • @Tarodev
      @Tarodev  3 роки тому +2

      Gamifying anything makes it fun to learn. Imagine if we earned experience ironing our clothes, or washing the dishes. You better believe I'd be a level 80 ironer. But in reality, I've ironed once in my entire life lol.

    • @svendpai
      @svendpai 3 роки тому +1

      @@Tarodev i feel you, gamification can be a strong asset

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

      This video is probably informative if you started coding 5 minutes ago. But its too rudimentary for anyone else.

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

      @@RealisiticEdgeMod I mean yeah... I don't think the purpose of the video was to make you an expert on generics, but a lot of people might not have know about them or how to use them properly. I'm pretty new to coding and even though I knew about generics I found the video very helpful for clarifying and expanding upon my knowledge.

  • @zingutis
    @zingutis 4 місяці тому

    You got me with "Legolas" :D Was thinking the same. What other archers are out here in movies? Hawkeye from Marvel?

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

      It's a short roster

  • @TheKr0ckeR
    @TheKr0ckeR 3 роки тому +1

    I love your titles! :D

    • @Tarodev
      @Tarodev  3 роки тому +1

      Hope I'm not pushing it a bit far with this one, lol

  • @alifarhadali5580
    @alifarhadali5580 3 роки тому +2

    great work keep going

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

    May i suggest, when you are walking us through code, can you please zoom in a little for code to be more visible. Thanks.
    Ps: love your tutorials.

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

    You always make very interesting and well explained videos! You do great work! I always learn something new! Thank you!

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

    HEY! Love your stuff! What are the smooth jams you got runnig in the background???

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

      I've slowly compiled a bunch of royalty free tracks over time. Glad you enjoyed them 😊
      If you really want I can host them for you

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

    Excellent tutorial about generics, we are very lucky that you share this stuff with us sir.
    I would love if possible that you give some hints on the best architecture for a videoadventure where objects unlock dialogues and areas, and also depending on the answers given to a certain NPC, this propagates to the branching dialogues of not only this but ther NPC in the world but currently not in the scene, affecting the main storyline and the behavours of those NPCs towards the main character. I don't know what would be the best way to handle such complexity with so many NPCs, dialogues and object triggers affected. If I think of events and listeners, won't the code end up with lots of conditionals. Is there a cleaner way to do this?

  • @SlimeWithClass
    @SlimeWithClass 3 роки тому +1

    Lmao the discord plug, love it!

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

      And did it work...? Will I see you in there? 😉

  • @andrzejkulakowski
    @andrzejkulakowski 3 роки тому +1

    Useful stuff, and when it comes to archers, then there is the hooded man ;)

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

    Tarodev amazing videos brah keep it up its so fun to watch also teaches a lot ^^

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

    Thank you

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

    This was perfect

  • @jean-michel.houbre
    @jean-michel.houbre 2 роки тому

    Very informative. Thanks!
    On the other hand, I don't see the point of the HeroHelper class: you have to create a helper for each hero, and using ForceHeroToAttack is not easier or more flexible than using Attack? In addition, we manage 2 variables: the hero and his helper. I must have missed something ... We can define the Attack method as virtual and overload it in the child classes.
    I also do not see the point of increasing the code with HeroFactory compared to the use of constructors :
    - with constructor : Mage mage = new Mage ("Gandalf", 100);
    - with HeroFactory : Mage mage = HeroFactory ("Gandalf", 100);
    Also, if we want to have a different behavior from the mage (for example a mana field used by each attack), I have not succeeded in simply modifying HeroFactory.

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

      In that case you will need a generic class that implements IAttack, and now you can send there Archers, Mages, Warriors who need to know how to attack (for example the mage uses mana, the warrior uses fury, etc) but the implementation is inside every singular class

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

    Love your dummy data :) print(420) all day long!!

  • @kylekeenan3485
    @kylekeenan3485 10 місяців тому

    Amazing thank you.

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

    ok, very nice, but how to make a Factory which can get parameters for all kind of Heros ?

  • @ragerungames
    @ragerungames 3 роки тому +1

    soon your channel will have many many subs! maybe 100k? 200k? 1mil and even more.... I have gone into the past and watched each video..

    • @Tarodev
      @Tarodev  3 роки тому +1

      You're here in the early days. A true original gansta 😉

  • @stasdev
    @stasdev 3 роки тому +1

    Hahaha title is pog

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

    When should I use generics?

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

    thanks for this tutorial, really clear, as usual !

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

    Okay so I finally came to convert my mod system to use generics, because right now I'm using a struct to hold my settings which includes a variable for intVal, floatVal, boolVal... so of course you can imagine a lot of wasted variables there (presumably wasted memory). I thought it would be better to just have a basic generic value to replace the previous 3 (if not more as I grow the game and invent new modifications). Problem is, I'm struggling to get these little guys in a list. List modList = new List(); doesn't work. Of course I can specify the list to be a specific type eg List

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

    You had me @ dark souls

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

    Genetics generates a function for each type it gets used if I remember correctly right? Kinda like syntactic sugar

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

    I love your stuff, just found this chance a few weeks ago, have you done any working with making UIs work with arrow keys only?? Like if it were an old fashioned computer?

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

    Could you just put IPing everywhere instead of the generic T? like dont use generics and just use the interface? What can generics do that polymorphism cant?

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

      Generics is more performant as it doesn't require boxing and unboxing. Too much to type here but google unboxing. Good question 😉

  • @yahyasbini
    @yahyasbini 4 місяці тому

    Great !

  • @CyCloNeReactorCore
    @CyCloNeReactorCore 3 роки тому +2

    title gore, but *very* good video taro, i learned alot about generics, there were a few "AHA!" moments for me, thank you!

    • @Tarodev
      @Tarodev  3 роки тому +3

      That's EXACTLY what I was trying to achieve!

  • @privatesocialhandle
    @privatesocialhandle Рік тому +1

    C#: Let's do List.Add(1)
    Tarodev: Nah, let's do List.Add(69) ha 😏
    Edit: Legolas sounded like "Legal Ass" 😮 😂. Not sure if it was intended or just an accent thing. I love his vid (on the educational and comical aspects)
    PS: excellent content.

  • @5q11
    @5q11 3 роки тому

    Great video! This reminded me of one of the problems I thought could be solved using generics but I couldn't. Imagine using ScriptableObject architecture similar to the one described in Unity learn videos, where you store your variables as IntVariable, FloatVariable SOs and reference them in your classes. Now lets imagine UpgradeData class which would have to take either of thees types as a single variable - UpgradeValue. But you can't do that with generics because you have to define type at compile time. Any ideas on how to solve this? Not much info on the internet.

  • @TwinStick
    @TwinStick 3 роки тому +2

    The wrongness in this title is just perfect 👌 🤣

  • @muratcanagic
    @muratcanagic 3 роки тому +3

    Adding 69.. Man of culture.

    • @Tarodev
      @Tarodev  3 роки тому +2

      I'm just realizing now how many adult references I packed into this video...

    • @TheKr0ckeR
      @TheKr0ckeR 3 роки тому +1

      @@Tarodev well there is 420 too..

    • @Tarodev
      @Tarodev  3 роки тому +1

      @@TheKr0ckeR completely random number sir

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

    im failing to understand the herohelper? why create a herohelper of type warrior that inherits from hero? In a game, what is herohelper?

  • @Equisdeification
    @Equisdeification 3 роки тому +1

    In this case, Isn't shorter and more clear to just write this: (below)? I get this is just an example but I'm asking because maybe I'm missing something here.
    void PingMap(IPing ping)
    {
    ping.PingMap();
    }
    When I found generics and started refactoring my code to include them, I swear I removed at least 400 lines of code from the hole project limao

    • @Tarodev
      @Tarodev  3 роки тому +1

      You're absolutely right haha. That's why in editing I added that disclaimer about it being an advertisement for interfaces and not generics. Sometimes when you wing a segment it turns out sub-par lol. Hopefully it taught some people about the power of interfaces, at least...

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

      @@Tarodev Haha it's fine! Thank you for the work that you are doing!

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

      If the IPing instance was a struct it would be boxed when passed into the method with an interface as a parameter. The generic version would not.
      Not particularly to do with this example but more broadly:
      The generic version could also be modified to add more constraints with little issue, whereas the interface version would require creating more structures to constrain further.
      Generics also allows methods to return the exact type a method is constrained to.

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

      @@vertxxyz Thanks for detailing that. I strongly debated including the performance benefits of avoiding boxing, but chose to leave it out and keep the content strictly functional based.

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

    My man what is the background music :P

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

    Hey thanks a lot for this, am a bit late to the party but i have an offtopic question, what is that "Program.cs" and how is it getting executed while being "naked" like that, there is no class declaration in it or anything, it just runs ? I was really surprised when that first Print worked lol, so can someone please point me toward the light here xD

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

      Hey brother, haven't seen you around recently.
      It's the new top level statements. The goal was making it simpler for new c# devs and not blasting them with a bunch of concepts in the boilerplate. Here's a link: learn.microsoft.com/en-us/dotnet/csharp/whats-new/tutorials/top-level-statements

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

    I think this tutorial got recommended to me cause you used dark souls as an example

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

    really useful! thanks!! also got a good laugh out of "nipplebutts" hahah

  • @juke-duke
    @juke-duke 3 роки тому +1

    How did your code run without a Main method?

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

      In .net 6 you can now remove the standard boilerplate and write directly in the top level! It also has default imports of commonly used namespaces so it doesn't crowed your scripts 😊

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

    Why make the HeroHelper generic? Couldn't it just have a property of type Hero instead of T?

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

      In this case, probably cause it was just an easy example, but it's kinda a personal preference thing. Sometimes the property makes sense, sometimes the generic makes sense.
      It's a way to differentiate between a "is a" relationship and a "has a" relationship to. With generics you can say: "this is a Warrior Hero Helper" instead of "this is a hero helper that has a warrior"
      So it helps organize things. One thing he didn't cover is that generics can be used with implementations of an interface too, as an example, if you had heros, enemies, and puzzle blocks, and you wanted to save their in-game locations, instead of making them all inherit from a "baseUnit" you can have them implement a "ISaveable" and pass them to a "SaveHelper where T is ISaveable" and the save helper could manage saving all your game data without caring about inheritance structure.
      There are, of course, other ways of doing this, but it's one tool in the belt and is good to know as an option.

  • @subhadas
    @subhadas 3 роки тому +1

    The title lol

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

    Thanks kiwi Matt Walsh

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

      Aussie* And also, that's the first time I've been compared to him 😅

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

    why no one is taking about the 69 and 420 perfectly used?

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

    I think everyone agrees that we need more *generic* tutorials outside of the usual game dev ones.
    (HAH!! see what i did there !?)

  • @restushlogic5794
    @restushlogic5794 3 роки тому +1

    Please use bracket like this. It would be help for a newbie dev.
    {
    //code
    }

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

      @Dyanosis yes, that's for professional. Many asset on Unity use the non-in line bracket. It is easy to read the code for everyone.

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

      @@restushlogic5794 Inline open-braces are not "for professionals" - they're just a preference, and they don't change anything about the code's logic.
      This:
      void Method() {
      //code
      }
      Is exactly the same as this:
      void Method()
      {
      //code
      }
      It really doesn't reduce readability. You can tell when a block scope ends by the closing curly-brace in either style.

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

      @@Dxpress_ I don't understand

  • @narkopraxis602
    @narkopraxis602 3 роки тому +2

    Challenge accepted. I'm gonna make a game where you control a chair. It will be a idle, timing game where you're goal is to wait until someone is about to sit on you, then duck out at the last minute to make them fall on their heads, awarding you blood to spend on chair upgrades, Increasing your "bps" blood per second.
    Eventually, your chair will be so amazingly appealing that peeple will be flocking to your cushion by the thousands and tens of thousands and single chairleggedly, you can cause the mass extinction of the human race.

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

      Time to get rid of all of the chairs in my house before they rise up against me. Thanks for the warning pal

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

      @@libberator5891 anytime. Here all day

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

      @Dyanosis all day. Every day. 😜

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

      You'll need starting classes... Recliner, stool, etc

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

      @@Tarodev each class should have branching upgrades that are almost virtually unobtainable without microtransactions, the stools legendary version should look like "poop in a cup"
      🤣

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

    heyyy why did you changed the funny name?

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

      Once I started getting sponsored by unity I thought I'd clean up the titles a bit. I'll keep my in video personality the same though 😊
      Glad you appreciated my immature humour though

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

      @@Tarodev oh, it's understandable, i think getting sponsored makes people more "decent" lol, but i'm glad you're keeping the personality, reading about putting things inside you made me laugh too, so i guess i share the same immature humor XD but those kind of silly jokes gives you more personality and makes the video a bit more didactic? i think :)

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

    using ConsoleApp1;
    var warrior = new Warrior()
    {
    Name = "Warrior",
    Damage = 100,
    };
    var helper = new HeroHelper(warrior);
    helper.Print(warrior);
    warrior.Attack();
    namespace ConsoleApp1
    {
    internal class HeroHelper where T : Hero
    {
    public T Data;
    public HeroHelper(T data)
    {
    Data = data;
    }
    public void Print(T input)
    {
    Console.WriteLine(input);
    }
    public void ForceAttack()
    {
    Data.Attack();
    }
    }
    }
    public abstract class Hero // Base class
    {
    public int Damage;
    public string? Name;
    public void Attack()
    {
    Console.WriteLine($"{Name} did {Damage}pts of damage.");
    }
    }
    public class Mage : Hero
    {
    }
    public class Warrior : Hero
    {
    }
    public class Archer : Hero
    {
    }

  • @EduardO-gm7hx
    @EduardO-gm7hx 3 роки тому +1

    🤣🤣🤣🤣

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

    and then people make fun of JavaScript because its "confusing"

  • @СтасДідусь
    @СтасДідусь 3 місяці тому

    thx , it war very useful

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

    The complete guide is not "completely" accurate... I have a problem I can not figure out.
    I have a class that takes an emun like this:
    public class CpuInfo where T: System.Enum
    {
    public T status; // T is an enum with [FLAG] attribute
    public void SetStatus(T stat)
    {
    // This is not possible - why? (but is possible to do instantiatedCpuInfo.status = instantiatedCpuInfo.status | stat; from outside the class)
    // status = status | stat;
    // Equal operator works
    // status = stat;
    }
    // .... removed ..../
    }
    If I instantiate the class with this enum:
    [Flags]
    public enum CpuStatus
    {
    None = 0b_0000_0001,
    CPU1Running = 0b_0000_0010,
    CPU2Running = 0b_0000_0100,
    CPU1Paused = 0b_0000_1000,
    CPU2Paused = 0b_0001_0000,
    CPU1Halted = 0b_0010_0000,
    CPU2Halted = 0b_0100_0000
    }
    Instantiated by:
    var cpuInfo = new CpuInfo();
    Then I perform:
    cpuInfo.status = cpuInfo.status | CpuStatus.CPU1Halted;
    It works...
    I can not figure out what I am misunderstanding about the generic classes...
    Any suggestions?