C# Generics Tutorial: Whats and Whys | Mosh

Поділитися
Вставка
  • Опубліковано 19 січ 2025

КОМЕНТАРІ • 135

  • @johnoweston8976
    @johnoweston8976 5 років тому +10

    I never comment on videos.
    But I really couldn't get my head around Generics.
    And watching this video really helped.
    It all became clear 3 mins in and I still watched it to the end!
    Appreciate the video and the excellent examples, thank you!

  • @shaihulud4515
    @shaihulud4515 8 років тому +4

    I'm new to coding - in general, not only in c#. And you're definitively my teacher - you know what you are talking about. What impresses me the most is that you have obviously some sort of didactics to your thematics. Highly appreciate that! Keep doin vids, they're awesome!

  • @cocoscacao6102
    @cocoscacao6102 5 років тому +5

    This guy is an absolute master when it comes to passing the knowledge on to others. I highly recommend to check his tuts anywhere (I've been watching C# tuts only so far). Mind that some of the more complex ones might take a 2 or 3 reviews to fully get, cause they're... well about complex subjects... But all of the details are there.

  • @willharrison-builds
    @willharrison-builds 9 років тому +12

    this is only my second video of yours to watch, but I have to say they are very high quality and very well done. keep up the good work and thanks.

  • @JohnnyB43
    @JohnnyB43 7 років тому +2

    Very clear, concise and thorough. Thanks a lot.
    I like how you narrate what the code / symbols mean - that really helps a lot.
    That is one thing that for me makes C# a real pain - that it is not easy to read at all because instead of words it uses e.g ":" or "#" to mean something. Apart form being difficult to read, you cannot exactly Google : in C# and find out what it is doing.

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

    Thank you, this video was much easier for me to understand than others on UA-cam.

  • @angel_machariel
    @angel_machariel 9 років тому +2

    This is the second tutorial you have published that I watched. You're doing a damn good job!

  • @fadmad7257
    @fadmad7257 7 років тому +1

    just bought all your C# courses on udemy fundamentals, OOP, and advanced. Thank you so much. honestly the only confusing thing about your courses is how well you explain concepts.

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

    Best tutorial on generics. Thanks Mosh!

  • @iosifpuha6114
    @iosifpuha6114 11 місяців тому

    this is sooooooo good even 8 years after, you a G

  • @osinnowo
    @osinnowo 7 років тому

    You're very very very extra ordinary and extremely good. You're the best programming teacher I've ever seen.

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

    0:10 - problem
    2:44 - create generic list
    6:32 - create generic dictionary
    8:49 - constraints

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

    pretty concise video, thank you mosh. now I'll dive into details !

  • @adeelmalik6002
    @adeelmalik6002 7 років тому +1

    Mosh you are the best instructor i have even studied Thanks a lot .........

  • @akhileshbaldi4696
    @akhileshbaldi4696 8 років тому

    Mosh you are an awesome teacher ! like the way you make things so simple to understand!

  • @CarlHamilton1914
    @CarlHamilton1914 7 років тому

    What a great video! I've seen generics in code but haven't really understand what they were doing until now. Thanks!

  • @rajarathinambalasaubramani8610
    @rajarathinambalasaubramani8610 9 років тому

    Really Good Just Saw your Video i did not see fully i saw little bit because i am in office so i did not see i see in my Home. You are are a Good Teacher

  • @briandoesdev
    @briandoesdev 9 років тому +5

    Your a great teacher! Can't wait for the ASP.NET course!

  • @Hardgraf1
    @Hardgraf1 9 років тому +4

    fantastic. perfect for my interview tomorrow!

    • @moshfeghhamedani
      @moshfeghhamedani 9 років тому +2

      +Tom Hutch How did the interview go? :)

    • @hardgrafter3031
      @hardgrafter3031 8 років тому +6

      +Moshfegh Hamedani Got the job. Been there 8 months 😀

  • @ahmedshalaby1878
    @ahmedshalaby1878 4 роки тому +1

    Dear Mosh,
    I am new to c#, and i understood the using generics but still confused about constraints.....
    i see that using generics is good to create a generic class,
    But adding constraints , just makes it not generic " that's what i get "
    in this case what is the difference between the below 2 styles ( with and without generics )
    Method1:
    --------------
    class Constraints where TBook : Book
    {
    public void FirstMethod(TBook book)
    {
    }
    }
    Method1:
    --------------
    class Contraints21
    {
    public void FirstMethod(Book book)
    {
    }
    }

  • @scm2728
    @scm2728 8 років тому

    Amazing video ! Please do some video like this for exception handling. Good job!

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

    Daste shoma dard nakone. I was stuck on this concept. Berfarma T. =)

  • @danish162
    @danish162 8 років тому

    dude you are awesome, I learned about so many little things in things which I found very helpful, Thanks a lot :-)

  • @R0T0Q
    @R0T0Q 5 років тому

    Clear and concise! Excellent!

  • @o.429
    @o.429 5 років тому

    This is the perfect video for me. I was so confused about this topic. Everything is clear now. :)

  • @rodricmontique6294
    @rodricmontique6294 5 років тому

    Never mind, i figured it out lol Thanks man, big help!

  • @CAPS_AMERICA
    @CAPS_AMERICA 4 роки тому +2

    Hi Mosh, do you have a course dealing with how to use those C# interfaces like IEnumerable, IComparable, etc, in detail and why use them? Thanks

  • @beri4138
    @beri4138 4 роки тому +1

    As a beginner to C#, holy hell this is some extreme shit my dude. Everything in your code passes through like 18 levels of abstraction.

    • @BobrLovr
      @BobrLovr 4 роки тому

      don't use the word abstraction if you're a beginner please, it's pretentious. Haha just messin' with you, yeah sometimes you go through the basics and you think you're all fine and dandy with classes, methods, variables, if statements, for statements and all that jazz. But then you come across the next video and it's all
      crazy =shit
      bet.you(didn't think you(could do this));

  • @patkartarun
    @patkartarun 4 роки тому

    Nice sir short and sweet (understandable)

  • @niclast7600
    @niclast7600 5 років тому

    I got examination from home in c# this week. Been trying to use objects, but that didnt work as planned. So I think generics is what I need, you also explain the exakt setup I need for this :).

  • @troyincarnate8105
    @troyincarnate8105 4 роки тому

    really good explanations.

  • @GarryWatson111
    @GarryWatson111 6 років тому

    Thanks Mosh. Very useful.

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

    Nice and Easy , Thanks

  • @MDM666666
    @MDM666666 9 років тому +1

    Thank you sir you are a great teacher.

  • @baurks
    @baurks 6 років тому

    Hi Mosh, I enjoyed watching this nice tutorial. Thank you! Can you please explain why should we use IComparable instead of IComparable?

  • @SBTRIS
    @SBTRIS 4 роки тому

    Love your style - question though @16:13 you state _value is object, why not make that of type T?

  • @tigerboom9030
    @tigerboom9030 5 років тому

    Lets say i am doing a generic class call it Node. In only one method i would like that T be Node. So if we look at Node it would be Node... i am quite new...
    So how can i do it?
    I believe that Node is list. And is has property named: T data.

  • @Abu.Karrar
    @Abu.Karrar 9 років тому

    You've made my life simple, thanks!

  • @funnydadcrazyson4112
    @funnydadcrazyson4112 8 років тому

    Valuable content... Thanks for you hard work making this video and sharing it. Great video !!! Awesome.

  • @armandasbarkauskas4485
    @armandasbarkauskas4485 8 років тому

    You knowledge is unlimited :o, WOW, well done!

  • @boi-huela4877
    @boi-huela4877 7 років тому

    Very helpful explanation. Thanks a lot!

  • @evviaccia
    @evviaccia 6 років тому

    salam mosh khubi? chetori? :) i can speak a little bit persian. thanks for your videos. they are awesome. wish the best for you brother.

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

    very cool, many thanks

  • @daniel_keen
    @daniel_keen 9 років тому

    Great video, thank you!

  • @AS-sb8uo
    @AS-sb8uo 9 років тому

    awesome , you should create video on struct vs Classes , and when to use them

  • @mokshaGyanRam
    @mokshaGyanRam 7 років тому

    Awesome Teacher Sir ... Your Really Good :)

  • @sankarprasadpanda9431
    @sankarprasadpanda9431 8 років тому

    your videos are really informative..
    nice one

  • @shawn129386
    @shawn129386 8 років тому

    Great job. Thanks a lot for this awesome video :)

  • @jz1838
    @jz1838 9 років тому

    Thanks for your effort. I will follow you. Thanks

  • @danieldo2281
    @danieldo2281 7 років тому

    what keyboard do you use? sounds good

  • @ritamghosh3550
    @ritamghosh3550 5 років тому

    Very good tutorial, thanks a lot

  • @danigolmestre
    @danigolmestre 8 років тому

    Very Good! Thanks

  • @SheshagiriPai
    @SheshagiriPai 9 років тому +2

    You know your stuff man, awesome (Y)

  • @japhethjay4880
    @japhethjay4880 9 років тому +2

    Beautiful tutorial really love it, if i may ask what is the theme you are using on visual studio?. Really like it will love if you could share that am new to the visual studio environment.

    • @moshfeghhamedani
      @moshfeghhamedani 9 років тому

      +Japheth Jay Hi Japeth, I'm using the default dark theme in VS 2013. I've also installed ReSharper and it adds some extra colors to the theme.

    • @japhethjay4880
      @japhethjay4880 9 років тому

      ReSharper hmmm Don't know how to get that, but will try searching online for it thanks though, cause its the same am using but yours is way more sleek

    • @moshfeghhamedani
      @moshfeghhamedani 9 років тому +1

      It's a commercial plugin for VS.

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

    Isnt the discount calculator supposed to be just a method that takes an Product as a parameter? It does not need to be generic. Am I missing something?

  • @aditheorigin4926
    @aditheorigin4926 9 років тому

    What shortcut have you used to search file (program.cs)? [time 3:41]

    • @tevoj
      @tevoj 9 років тому +1

      +Adi TheOrigin ctrl + ,

    • @aditheorigin4926
      @aditheorigin4926 9 років тому

      +Estevan Jantsk I use the same but the control looks different!

    • @tevoj
      @tevoj 9 років тому

      +Adi TheOrigin I think that's because he's using another version of visual studio. Here looks different to but the functionality is the same.

    • @aditheorigin4926
      @aditheorigin4926 9 років тому +1

      +Estevan Jantsk : oh! okay.
      well, thanks for your response :)

  • @hazemelamir2083
    @hazemelamir2083 5 років тому

    very very good
    you are the man

  • @yazilimciningunlugucom
    @yazilimciningunlugucom 7 років тому

    Thank you for the tutorial.

  • @FuzzyDPozzy
    @FuzzyDPozzy 6 років тому

    thank you so much for the tutorial it was really well explained

  • @FortyTwoAnswerToEverything
    @FortyTwoAnswerToEverything 9 років тому

    Mosh excellent tutorial. Thank you! When will you get into C#/XAML in store apps? edit: What do you use as your microphone? Very clear.

    • @LazarRedDevil95
      @LazarRedDevil95 9 років тому

      ***** Nice, looking forward to asp.net mvc course . Thank you for sharing your knowledge

  • @shamus306
    @shamus306 7 років тому

    What would happen at runtime if the Type T didn't have a parameterless constructor and we called DoSomething() to instantiate an object of said T?

  • @exSnake
    @exSnake 9 років тому

    You should do a tutorial about ICommand interface for WPF, it's annoying like the Events/delegate, i founded that tutorial nice!

    • @exSnake
      @exSnake 9 років тому

      +Programming with Mosh I've followed the advanced tutorial on Udemy, it's really good, so i decided to follow the intermediate too even if i've read books and blogs about classes, OOP & co., i will leave a reviews for both at the end of the intermediate one. For now, u did a very nice job!
      About ICommand, i think that the annoying part is related in all that concerns concept of mvvm! Would appreciate a nice video/blog or a udemy lesson on it! I didn't know if u should use it on your own work in ASP:net, but it's a main concept in WPF and in the iOS application (objectiveC)

  • @vickyvirat5166
    @vickyvirat5166 6 років тому +2

    Probably one of the best explanation for Generics, plus very good explanation of piece by piece of Genrics. hanks!

  • @amirdaraee
    @amirdaraee 6 років тому

    بسیار عالی بود، مردم انقدر این ویدئو های هندی رو دیدم، اصلا قابل فهم نیست لحجشون !!

  • @revenez
    @revenez 5 років тому

    Brilliant, thank you.

  • @jehnzcode
    @jehnzcode 4 роки тому

    why is it that in c# we are force to set the datatype in our variables eg. string, int, bool etc. but also allows us to use generics. Why is that? I thought c# is a strong-type language.

  • @gyohza
    @gyohza 5 років тому

    Hmm. But what if you're building an API with response models? Generics are very useful in wrapping database query values.

  • @nlarsensmith
    @nlarsensmith 7 років тому

    Hello Mosh, when we apply constraint class to a generic say
    " public class DiscoutCalculator where TProduct : Product "
    is same as saying
    " public class DiscountCalculator " ?

  • @CanadianMang
    @CanadianMang 6 років тому +7

    I can't follow this for some reason. I understand what classes and objects are but I am having trouble understanding this.

    • @tomservo75
      @tomservo75 4 роки тому +1

      You're not alone. Mosh has a tendency to zoom through presentations without explaining anything. #1 rule of teaching, NEVER just take for granted that your students "get it." You must explain in painstaking detail. But not Mosh. I've already watched the first 2 minutes FIVE times and I still don't understand what he's even trying to solve. Explanations are above him, you see. He just throws the line "public Book this [int index]" out there, completely oblivious to the fact that there may be people who don't understand that syntax. "What do you mean," says Mosh. "This is so easy I was doing it in nursery school. You must be too stupid for me to have to explain it to you." On average I tend to exit his videos about 11.8% more confused than I went in with. Not good. And for the love of God, do NOT take a class with this charlatan. Never explains anything, never answers student questions, just takes your money and throws you to the wolves. And if that's not enough, makes you buy a $300 per year software that he dogmatically insists is the best thing out there and you're stupid not to use it. I'm willing to bet he's getting a little commission from Resharper, he acts more as their salesman than a teacher.Positively HORRIBLE excuse for an instructor.

    • @ufukseyithan
      @ufukseyithan 4 роки тому

      @@tomservo75 It is acceptable he does not cover the basics. It is also acceptable where he would not explain anything that is not related to the subject of this video, the Generics. I am here to grasp the Generics; not for example, what "public Book this [int index]" does.

    • @BobrLovr
      @BobrLovr 4 роки тому

      @@tomservo75 dude if you don't know what basic shit is why are you here? Go back to helloworld beginner tutorials man.

  • @tonticioleg3213
    @tonticioleg3213 8 років тому

    Great.
    Thank you!

  • @Exachannel
    @Exachannel 9 років тому

    Veru useful! Thanks.

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

    Thanks!

  • @krantimadineni585
    @krantimadineni585 8 років тому

    Excellent

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

    one reason people can't get how Generics work is the lack of scenarios. you may see a good scenario once a year. So you know how it works you just don't have an opportunity to use it.

  • @rhubarbcheese
    @rhubarbcheese 9 років тому

    what function has 'this' on " Book this[int index]"? and I think it would be good to explain what where T : IComparable is, as it does not look like any other code.

    • @moshfeghhamedani
      @moshfeghhamedani 9 років тому

      +rhubarbcheese This is an indexer. We use that to implement indexers on classes. An example of that is the Array or List class. They have indexers so you can access elements by an index: array[0]

    • @rhubarbcheese
      @rhubarbcheese 9 років тому

      Thank you! Im aware of this now. But it still doesnt explain what exactly it is..! It looks like an extension method a little, doesnt it? And im thinking now that... does it make sence at all, that when I combine those symbols together I make an indexer, or, is it that.... its just how it is. Do you know?

  • @matthewel-sirafy7266
    @matthewel-sirafy7266 6 років тому

    is this the same video from your unity course??

    • @matthewel-sirafy7266
      @matthewel-sirafy7266 6 років тому

      Programming with Mosh really? I found a course on udemy called c# advanced topics and it was taught by someonw who looks like you with the same video type

  • @elchino7672
    @elchino7672 5 років тому

    3:41 How you open find pop-up on 3:41 ?

  • @naveenkanagala1512
    @naveenkanagala1512 6 років тому

    Thanks you so much

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

    Is it used often?

  • @rodricmontique6294
    @rodricmontique6294 5 років тому +2

    My problem is that you leave us hanging in some cases, when you create something like a product constraint, you never actually show how it is used then you move on the creating a type new() constructor constraint and now i know how to create these things and what they are but still not clear on their real world application.... I have so much more to lean :-(

  • @ibrahimabdalla1642
    @ibrahimabdalla1642 5 років тому

    Please please please make a tutorial on how to make a windows forms application like a calculator.

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

    12:23 the generics get smaller everytime we go code down 😂😂😂

  • @rawal16
    @rawal16 7 років тому

    well explained

  • @rinusluijk3514
    @rinusluijk3514 9 років тому

    Hey, Mosh, how do you get your entire IDE's background black/grey like that? I've tried, but I can only get the window with the code like that, not the other windows.

    • @rinusluijk3514
      @rinusluijk3514 9 років тому

      Oh ok, I see now. Thanks a bunch, it looks much better.

  • @erkandotnet
    @erkandotnet 8 років тому

    very good

  • @tomservo75
    @tomservo75 4 роки тому

    what does the "this" in "public Book this[int index] mean? I see the word used in so many contexts it's confusing.
    As for the List class, I'm really confused here. You've already got a class BookList. So why do you need to create an object list, why not just say public List and be bloody done with it? It's working backwards. "I want a variable of type int but first I'm going to create an object and then use generics to make it an int." Huh???? That makes no sense. This whole "Eeeh, don't worry about what data type it is, we'll figure it out later" just seems like VERY bad practice.

  • @mastertt7929
    @mastertt7929 9 років тому

    Hi Mosh,
    Can you please make a video about how to accessing a SQL Server?

  • @realsoftgames7174
    @realsoftgames7174 7 років тому

    @9.20 what is that line called. i cant remember for the life of me.

  • @thelobo581
    @thelobo581 6 років тому

    Int can be nullable int?

  • @zardify_
    @zardify_ 9 років тому

    2:17 I just made this mistake, and came here accidentally not knowing what "Generics" mean... :3 Shame on me! :D Thank you!

    • @zardify_
      @zardify_ 9 років тому

      Bernát Gyovai Uhm. Not really a mistake as far as i know... I'm using a Dictionary() because i need to store strings, integers and floats in the same "array". But then i need to cast them to store, and i need to cast them to retrieve.... Is this a mistake? Is there another way to do this?

  • @FuzzyDPozzy
    @FuzzyDPozzy 6 років тому

    dam those youtube ads lmao i saw 6 ads while watching the video lmao

    • @ibrahimabdalla1642
      @ibrahimabdalla1642 5 років тому

      lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao lmao.

  • @D4rkC1own187v2
    @D4rkC1own187v2 8 років тому

    Their is no audio.

  • @tannerpercival582
    @tannerpercival582 5 років тому

    Polymorphism in action

  • @SayWhaaaaaaaaaaaaaaaaaaaaaaat
    @SayWhaaaaaaaaaaaaaaaaaaaaaaat 5 років тому +1

    Your videos are good, but this one SUCKED. I think you choose the bad examples. Nobody gonna use generics for lists, for dictionaries and so on. Also other examples was too complicated to see any advantage of generics. AT least for me this video made me wanna avoid generics :)
    Best example where people could use generics is HTTP requests where you send objects and receive objects via JSON. So you say Http.Get(LicenceNumber); This will send get request and parse received JSON (in our case) to a Car class and will return it. This also very useful for POST requests where you define T with your class and request sender function serializes your class to JSON. This example would be much more useful then examples you showed. They give no additional value in your video IMO.

  • @mattshu
    @mattshu 8 років тому

    If I have a Persons (string name, etc) class to store in a list would it be better practice to use the existing List or make my own generic?

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

      ...What? List should already be a generic type; there's no reason to reinvent the wheel here.

  • @SydurRahman21
    @SydurRahman21 4 роки тому

    সম্পূর্ণ বাংলায় C# (C Sharp) শিখতে পর্যায় ক্রমে: ua-cam.com/channels/niMHMSJvYxGX0DAfz5SQkA.html

  • @avalon2199
    @avalon2199 8 років тому

    Nice

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

    kheili mamnon moshii

  • @keithkatane4854
    @keithkatane4854 4 роки тому

    The finder of lost children...

  • @sensoukami
    @sensoukami 6 років тому

    Waaay too many ads in this video...other than that it's good though.