C# Generics - The complete guide

preview_player
Показать описание
C# generics allow users to define classes and methods with a placeholder type. This provides amazing code re-usability while still retaining type safety.

In this video, I'll teach you what generics are, how to use them and provide a few real-world use cases to get your head around them.

I use game-like examples so you can see how you would use generics in your Unity development 🎮

=========

0:00 What are generics
1:20 Writing a generic class
11:36 Generic Type creation
15:13 Generics and Interfaces
Рекомендации по теме
Комментарии
Автор

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

DanPos
Автор

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

RAPHAELSC
Автор

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.

Briezar
Автор

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.

JamesMCrutchley
Автор

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

techoutlook
Автор

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

golosbezdoka
Автор

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

maciejp
Автор

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

kopilkaiser
Автор

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

geniusforever
Автор

fantastic and straight-forward explanation. thanks man :)

milosdamjanovic
Автор

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! :)

BlackoutGamingChannel
Автор

Phenomenal video, keep up the great work man!!

rileyfuller
Автор

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!

tommywilkinson
Автор

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

archastudio
Автор

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~

qiangpanchen
Автор

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 <T> 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<T> 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<itemData> & UIButton : Selection<buttonData> and hook up its selection event and that's it.
(and this is an inheritance example but it works just the same by composition).

gaelp.
Автор

Great video! one point i would have added is how generics work with inheritance. So you could also make a class WarriorHelper<Warrior> : 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.

BS
Автор

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

DotaEffect
Автор

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

stevancosovic
Автор

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

flipflap