I'd been looking to do some more research into generics so this hit at the right time mate! Also, sick thumbnail
@Tarodev3 жыл бұрын
A man who appreciates the art of thumbnails ❤
@RAPHAELSC Жыл бұрын
I am very impressed!!!! How you teach complex topic that even a begginner would understand and a pro would finally comprehend!
@Briezar3 жыл бұрын
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.
@Tarodev3 жыл бұрын
Pure random numbers ;)
@techoutlook92352 жыл бұрын
This is the explanation I am looking for. Thank you so much.
@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 Жыл бұрын
That's what I like to hear 😊
@TNothingFree3 жыл бұрын
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.
@tabooization1232 жыл бұрын
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
@tommywilkinson33 Жыл бұрын
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!
@maciejp8001 Жыл бұрын
Big thanks. Never before did I understood those as well!
@BlackoutGamingChannel2 жыл бұрын
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! :)
@gaelp.58474 ай бұрын
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).
@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 Жыл бұрын
Thanks for the like buddy 🙏
@geniusforever57803 жыл бұрын
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
@Tarodev3 жыл бұрын
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?
@milosdamjanovic7 ай бұрын
fantastic and straight-forward explanation. thanks man :)
@golosbezdoka2 ай бұрын
It was explained very well, thank you. Also, it looks like c# attributes are poorly covered on KZbin, please can you make a tutorial about them? 🙂
@GBSCronoo3 жыл бұрын
Best Tutorials on the net xD
@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.
@stevancosovic47062 жыл бұрын
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
@TheKr0ckeR3 жыл бұрын
I love your titles! :D
@Tarodev3 жыл бұрын
Hope I'm not pushing it a bit far with this one, lol
@rileyfuller83049 ай бұрын
Phenomenal video, keep up the great work man!!
@qiangpanchen67852 жыл бұрын
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~
@basicdogtrainings93893 жыл бұрын
Thanks Taro, for C# Generics today I learned more from you👏[Battle King
@archastudio26763 жыл бұрын
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
@Tarodev3 жыл бұрын
Glad you like them!
@samduss41933 ай бұрын
i was going over few Tutorial in generic and depress a bit.. this one click me :) right explanation :)
@Tarodev3 ай бұрын
I win!
@andradiusvolatius3 жыл бұрын
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.
@Tarodev3 жыл бұрын
These are the comments which make me feel good about what I'm doing. Yes I'd love to see your work
@SlimeWithClass3 жыл бұрын
Lmao the discord plug, love it!
@Tarodev3 жыл бұрын
And did it work...? Will I see you in there? 😉
@Vastlee3 жыл бұрын
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.
@Tarodev3 жыл бұрын
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.
@flipflap4673 Жыл бұрын
Great stuff! You taught me so much in very little time! Thank you.
@thenatedoggchannel9719 Жыл бұрын
Dude, thank you! Well put and understandable.
@DotaEffect3 жыл бұрын
Tarodev amazing videos brah keep it up its so fun to watch also teaches a lot ^^
@billyfrcs083 жыл бұрын
Thanks!
@chloe_the_cat28312 жыл бұрын
You always make very interesting and well explained videos! You do great work! I always learn something new! Thank you!
@svendpai3 жыл бұрын
Everything about this is so great, really nice and relevant topics!
@Tarodev3 жыл бұрын
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.
@svendpai3 жыл бұрын
@@Tarodev i feel you, gamification can be a strong asset
@RealisiticEdgeMod2 жыл бұрын
This video is probably informative if you started coding 5 minutes ago. But its too rudimentary for anyone else.
@svendpai2 жыл бұрын
@@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.
@alifarhadali55803 жыл бұрын
great work keep going
@MrSniper2k7 Жыл бұрын
Really enjoyed. Would love to jump into game programming.
@Tarodev Жыл бұрын
We'd love to have you 😊
@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.
@DJnoratos3 жыл бұрын
Great tutorial, thanks for good explanation
@rashidfarhan62233 жыл бұрын
This was perfect
@ragerungames3 жыл бұрын
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..
@Tarodev3 жыл бұрын
You're here in the early days. A true original gansta 😉
@rebondsdhistoires3 жыл бұрын
thanks for this tutorial, really clear, as usual !
@andrzejkulakowski3 жыл бұрын
Useful stuff, and when it comes to archers, then there is the hooded man ;)
@otgateway Жыл бұрын
Can you please do a playlist focused on core C#? It'd be so helpful
@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?
@Shahmuradov3 жыл бұрын
Put baby in me - Anything
@kylekeenan348511 ай бұрын
Amazing thank you.
@longuemire7482 жыл бұрын
Thank you
@Siberdt3 жыл бұрын
Why you are using void PingMap(T inputObject) where T : IPing{} if you can use the way w/o generics void PingMap(IPing inputObject){} ?
@zehsofficial2 жыл бұрын
Can you make a video about Quaternions and Rotation?
@XxTheArtisaNxX9 ай бұрын
HEY! Love your stuff! What are the smooth jams you got runnig in the background???
@Tarodev9 ай бұрын
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
@Ghanja0072 жыл бұрын
Love your dummy data :) print(420) all day long!!
@zingutis5 ай бұрын
You got me with "Legolas" :D Was thinking the same. What other archers are out here in movies? Hawkeye from Marvel?
@Tarodev5 ай бұрын
It's a short roster
@Soundy7773 жыл бұрын
You had me @ dark souls
@yahyasbini5 ай бұрын
Great !
@vrmsali3 жыл бұрын
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.
@azavier-a3 жыл бұрын
title gore, but *very* good video taro, i learned alot about generics, there were a few "AHA!" moments for me, thank you!
@Tarodev3 жыл бұрын
That's EXACTLY what I was trying to achieve!
@jean-michel.houbre3 жыл бұрын
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.
@agustinroman10742 жыл бұрын
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
@toni67333 жыл бұрын
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?
@privatesocialhandle Жыл бұрын
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.
@stasdev3 жыл бұрын
Hahaha title is pog
@TwinStick3 жыл бұрын
The wrongness in this title is just perfect 👌 🤣
@parsifal8232 Жыл бұрын
ok, very nice, but how to make a Factory which can get parameters for all kind of Heros ?
@pedro_12cs_fm Жыл бұрын
When should I use generics?
@shirosurfer88643 жыл бұрын
Genetics generates a function for each type it gets used if I remember correctly right? Kinda like syntactic sugar
@drudan89573 жыл бұрын
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?
@Tarodev3 жыл бұрын
Generics is more performant as it doesn't require boxing and unboxing. Too much to type here but google unboxing. Good question 😉
@darrylwolfe73592 жыл бұрын
im failing to understand the herohelper? why create a herohelper of type warrior that inherits from hero? In a game, what is herohelper?
@ewwitsantonio3 жыл бұрын
really useful! thanks!! also got a good laugh out of "nipplebutts" hahah
@BlackoutGamingChannel2 жыл бұрын
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
@muratcanagic3 жыл бұрын
Adding 69.. Man of culture.
@Tarodev3 жыл бұрын
I'm just realizing now how many adult references I packed into this video...
@TheKr0ckeR3 жыл бұрын
@@Tarodev well there is 420 too..
@Tarodev3 жыл бұрын
@@TheKr0ckeR completely random number sir
@5q113 жыл бұрын
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.
@Equisdeification3 жыл бұрын
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
@Tarodev3 жыл бұрын
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...
@Equisdeification3 жыл бұрын
@@Tarodev Haha it's fine! Thank you for the work that you are doing!
@vertxxyz3 жыл бұрын
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.
@Tarodev3 жыл бұрын
@@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.
@UndeadAlex3 жыл бұрын
My man what is the background music :P
@juke-duke3 жыл бұрын
How did your code run without a Main method?
@Tarodev3 жыл бұрын
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 😊
@alaslipknot2 жыл бұрын
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
@Tarodev2 жыл бұрын
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
@SaadTheGlad2 жыл бұрын
I think this tutorial got recommended to me cause you used dark souls as an example
@alaslipknot3 жыл бұрын
I think everyone agrees that we need more *generic* tutorials outside of the usual game dev ones. (HAH!! see what i did there !?)
@thishandleistaken3 жыл бұрын
Why make the HeroHelper generic? Couldn't it just have a property of type Hero instead of T?
@narkopraxis6023 жыл бұрын
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.
@restushlogic57943 жыл бұрын
Please use bracket like this. It would be help for a newbie dev. { //code }
@restushlogic57943 жыл бұрын
@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_3 жыл бұрын
@@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.
@restushlogic57943 жыл бұрын
@@Dxpress_ I don't understand
@narkopraxis6023 жыл бұрын
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.
@libberator58913 жыл бұрын
Time to get rid of all of the chairs in my house before they rise up against me. Thanks for the warning pal
@narkopraxis6023 жыл бұрын
@@libberator5891 anytime. Here all day
@narkopraxis6023 жыл бұрын
@Dyanosis all day. Every day. 😜
@Tarodev3 жыл бұрын
You'll need starting classes... Recliner, stool, etc
@narkopraxis6023 жыл бұрын
@@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" 🤣
@seanrendall54954 ай бұрын
Thanks kiwi Matt Walsh
@Tarodev4 ай бұрын
Aussie* And also, that's the first time I've been compared to him 😅
@subhadas3 жыл бұрын
The title lol
@СтасДідусь4 ай бұрын
thx , it war very useful
@mohammedayesh13782 жыл бұрын
why no one is taking about the 69 and 420 perfectly used?
@grezhz2 жыл бұрын
heyyy why did you changed the funny name?
@Tarodev2 жыл бұрын
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
@grezhz2 жыл бұрын
@@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 :)
@EduardO-gm7hx3 жыл бұрын
🤣🤣🤣🤣
@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 { }
@juancamacho479 Жыл бұрын
and then people make fun of JavaScript because its "confusing"
@berserker70917 күн бұрын
I understand generics, but I just don't know how, where, when to use it. that's the example I wanted to see, just 1 practical example not just "assuming". Your example have a separate class for all specific heroes. My class is only scriptable object where you select in enum if they are mage, archer etc. as well as their int damageAmount. Idk where to use generics in here.
@jesperkped2 жыл бұрын
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?