C# Generics - What they are, why they are useful, and how to create them

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

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

  • @marienoellemaltais
    @marienoellemaltais 6 лет назад +207

    You are such a great teacher. Many blessings to you. Simplicity is born out of a deeper understanding. Your tutorials are brilliant, like a breath of fresh air.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +15

      Thank you for the kind words.

    • @ValiRossi
      @ValiRossi 6 лет назад +8

      I agree. Every lesson is very consistent which helps in the learning process.

    • @thesophisticatedvelocirapt7320
      @thesophisticatedvelocirapt7320 3 года назад +5

      "Simplicity is born out of a deeper understanding" .........deep
      And yes, Tim Corey is the best

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

      Glad you're still with us. Sounds like a crazy experience, that tsunami... Hopefully one day I will learn French or find a translated copy of your book. Interesting to see you coding!

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

      And his voice as well 😍

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

    the beauty of this channel is it shows the practical usage of the theoretical concept.

  • @NM-tr1ii
    @NM-tr1ii 3 года назад +10

    You're my fav C# instructor. Period! I don't know what moment or who sparked the idea in your head that you decided to share your knowledge with the world, I'm just grateful that you did :-)

  • @linukkis
    @linukkis 4 года назад +5

    You're hands down the best teacher I've ever seen. Nothing is left unexplained, everything is always very clear and simple to understand. Thank you so much for inspiring other programmers through your awesome videos!

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      I appreciate the kind words.

  • @MS1022YT
    @MS1022YT 4 года назад +35

    Tim, great course.
    I like the way you explain "why" we would use Generics in real-world scenarios as opposed to just giving us "high-level" examples. Note that this teaching method sets you apart from other teachers.
    Also, you showed us an example where originally we don't use generics and then where (and why) we would use Generics (code reuse and decoupling logic implementation from actual data types).

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

      I am glad you found it helpful.

  • @neemapranay23
    @neemapranay23 4 года назад +8

    In India today (5th September) we are celebrating Teachers day. And for me, you are one of the best teachers I came across.
    Happy Teachers Day Tim!!

  • @volo7
    @volo7 4 года назад +4

    I haven't come across a better teacher for C# programming online. Thank you so much for what you are doing!

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

    what I iike about your tutorials like this one, is you don't over complicate things and I believe you always consider the level of skill of your watchers, explaining how and why things are done in a certain way. thanks Tim.

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

    Some people are born to teach, you one of them. Big thanks

  • @huzaifatinwala
    @huzaifatinwala 5 лет назад +12

    Best C# generics tutorial I have come across. Thanks, Tim. Really appreciate it.

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      You are most welcome. Thanks for watching.

  • @rodolfoeliezer1346
    @rodolfoeliezer1346 4 года назад +3

    The professor who doesn't assume understanding of some specific part of the explanation makes my understanding much better. Thank you a lot Tim Corey, for providing such a good content and yet free. Thanks from Brazil.

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

      You're very welcome! ... from Texas USA

  • @RahulSharma-ps1rf
    @RahulSharma-ps1rf 4 года назад

    Very good teaching, the best part is that first you explain what most of us do and show the best thing. Learnt a lot

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

    That is an excellent and simple explanation. I had some confusion about Generic methods, which are cleared now.
    Thank you.

  • @SuperLadly
    @SuperLadly 3 года назад +1

    Good one. Restriction and mentioning empty constructor was new to me. Thank you

  • @adityarane2758
    @adityarane2758 3 года назад

    Best Video in Advance Topics Playlist up till now. I loved the generic methods because I faced this problem in my previous organization.

  • @RalfsBalodis
    @RalfsBalodis 4 года назад +19

    0:00 - Intro
    1:33 - Creating a List of T
    4:03 - Why not to use ArrayList and why generics are useful
    11:10 - Demo app walk through pt1
    22:56 - The problem: repetition
    28:55 - Solving the repetition with generics; Demo application walk through pt2
    47:50 - When to use generics
    50:41 - Passing in more than one type generic

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +3

      Thanks! I added it to the description.

  • @DepressionAlgorithm
    @DepressionAlgorithm 5 лет назад +2

    Nice video as always Tim. Just a note on 35:20 for anyone interested in reflection:
    You can still grab the properties of a class, using reflection, without creating an instance of that class. This will compile and perform the same task: *var cols = typeof(T).GetProperties();*
    The instance was still needed in Tim's example though, since he's returning instances of that class in the Load method.

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      Yep, thanks for pointing that out.

  • @Jasszzz
    @Jasszzz 3 года назад +1

    Adicted to IAmTimCorey channel. Learning makes easy when we find the right person who can answer our questions without asking them. You are a Great teacher and your efforts are really amazing. Thank you so much Sir. Love from India

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

    Agree. One of the best teachers that I've found so far. Really clear, in-depth, not going on too fast (like some others just rushing on), so it's easy to follow and grasp. Brilliant! Thanx a lot. :)

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      You are most welcome. Thanks for watching.

  • @forresttucker168
    @forresttucker168 3 года назад +1

    I had no problems whatsoever understanding why it was done this way and how generics work, and I forsee it saving me a lot of work in the future. Thanks a lot Tim....

  • @ferrad1
    @ferrad1 6 лет назад +10

    Best free C# tutorial videos online !
    Thank you Sir !
    Keep up the good work !

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      Thank you for the kind words.

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

    Tim, again, an older but very timeless video. Thanks for the clear explanation on generics!

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

    Very clever example and code Tim. Just the right amount of complexity. Liked the reflection thrown in too. Thank you.

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

    This is great. You concisely explained a concept that i originally perceived to be intimidating and confusing. Bravo

  • @Jose67898
    @Jose67898 3 года назад

    Köszönjük!

  • @mbvisiombvisio1170
    @mbvisiombvisio1170 4 года назад +1

    Very helpful video. Generics explain in a practical way. Good teaching methodology. Not overcomplicated way of sharing your knowledge. Keep it simple Tim!

  • @n9434178
    @n9434178 6 лет назад +17

    Thank you Tim! This video improved my understanding of the use of generics.

  • @robertmerritt3284
    @robertmerritt3284 5 лет назад

    I have no idea how anyone could possibly give this video a thumbs down. Thanks Tim! You are awesome. I'll be heading over to Patreon real soon. Appreciate all you do to make our lives easier and wealthier!

  • @khaledbudajaja6137
    @khaledbudajaja6137 5 лет назад +1

    I have been using generics for a quite long time, but never managed to understand how to make one. you explained it very well.
    Many thanks Tim Corey

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +1

      Awesome! I'm glad I could add to your knowledge.

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

    Fantastic video Tim. What shortcut did you use at 23:46 to rename p to log in just that method? I tried web searching for it and cant find that same menu option you have with "Rename 'p' to 'log'".

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

      I renamed it manually and then used the Ctrl+. (Quick Actions and Refactoring) to do the rename everywhere.

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

      @@IAmTimCorey Thank you Tim. You're an awesome teacher.

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

    Thanks Tim for giving so much to the community.

  • @orcaowlwizco369
    @orcaowlwizco369 6 лет назад

    Man been watching and liking all your vids. They are solid. As a person finishing up a year's worth of c# classes, I still find your way of teaching really easy to understand, and the tips and way in which you deliver information is extremely helpful. Many thanks buddy!

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      You are most welcome. Thanks for watching.

  • @gleisonsubzeroKZ
    @gleisonsubzeroKZ 4 года назад

    thanks a lot for this excellent and wonderful tutorial about generics.
    I made some changes on reflection parts and I would share with you guys:
    public static List LoadFromTextFile(string filePath) where T : class, new()
    {
    var lines = System.IO.File.ReadAllLines(filePath).ToList();
    List outputList = new List();

    var properties = typeof(T).GetProperties();

    if (lines.Count < 2)
    throw new IndexOutOfRangeException("The file was either empty or missing.");
    // Splits the header into one column header per entry
    var headerColumns = lines[0].Split(',');
    lines.RemoveAt(0);
    foreach (var row in lines)
    {
    T entry = new T();
    var rowValues = row.Split(',');
    foreach (var column in headerColumns.Select((columnName, columnIndex) => new { columnName, columnIndex }))
    {
    var propertyRef = properties.SingleOrDefault(property => property.Name == column.columnName);
    if (propertyRef != null)
    {
    object typedValue = Convert.ChangeType(rowValues[column.columnIndex], propertyRef.PropertyType);
    propertyRef.SetValue(entry, typedValue);
    }
    }
    outputList.Add(entry);
    }
    return outputList;
    }
    public static void SaveToTextFile(List lstData, string filePath) where T : class
    {
    List lines = new List();
    if (!(lstData?.Count > 0))
    throw new ArgumentNullException("data", "You must populate the data parameter with at least one value.");
    var properties = typeof(T).GetProperties();
    lines.Add(string.Join(",", properties.Select(c => c.Name)));
    foreach (var row in lstData)
    {
    var rowValues = properties.Select(c => c.GetValue(row)).ToList();
    lines.Add(string.Join(",", rowValues));
    }
    System.IO.File.WriteAllLines(filePath, lines);
    }

  • @jayjayjaythebrand
    @jayjayjaythebrand 6 лет назад +4

    Everyone on here has benefitted from Tim in one way or another. Please subscribe to this man's Patreon, even if it's just the $1, that's nothing compared to the value he provides us for FREE! Support this guy!!!

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +2

      I appreciate the kind words and the support.

    • @StreetBladerBloke
      @StreetBladerBloke 6 лет назад

      Or sign up his courses to support him..

  • @MrMakgotla
    @MrMakgotla 4 года назад

    wish you could go around the world to teach the teachers how to teach... wow, I feel super happy to have came across your channel. "ke a leboga, thata"(Thank you very much(all the way from RSA))

  • @branislavpetrovic7486
    @branislavpetrovic7486 6 лет назад +3

    This is excellent and simple tutorial on C# generics. Thank you for your efforts and sharing your precious knowledge.

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

    Merci bien for your hard efforts to enlighten us Tim! You are an inspiration to start making a good code.

  • @Linkario86
    @Linkario86 5 лет назад

    Finaly an example where this is actualy useful. Now I understand the whole thing much better. Thanks a lot!

  • @testthisfordecficiencies
    @testthisfordecficiencies 4 года назад

    Great work Tim! Your syllable timing is perfect and I can run your video at 1.25 or 1.5 times and it still seems normal to my fast Brain.

  • @nafisiancastle
    @nafisiancastle 3 года назад

    I learned generics before. But today I learned why and when I should use it. Thank you !

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

    Thanks!

  • @nooraldeenali4628
    @nooraldeenali4628 4 года назад

    It's really helpful. Sir, only with your video did I learn why, I have to use generic. Thanks a lot.

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

    This was a very helpful tutorial. Thank you!

  • @charalampost769
    @charalampost769 5 лет назад +1

    Thank you for your videos, there are amazing. You help me so much to learn, and your sound and spelling is so clear to make it easy to understand for people that english isnt their native language.

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

      I am glad my content has been so helpful.

  • @patatas.m1317
    @patatas.m1317 5 лет назад +1

    You are so good sir, you explain it clearly. Even the topic is pretty advance for me, I can imagine things by your words. Thanks for making this video:)

  • @harag9
    @harag9 6 лет назад +3

    Great tutorial, thanks very much for your efforts on these - especially when it's 12:48 AM.. wow dedicated!

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +5

      Thanks! That's actually a pretty common time for me to be recording. I only get a few hours a day where I can record right now (from about 10pm to 2am). I am actually working on some soundproofing and other things so that I can record earlier in the day without degrading the sound quality. Once I get that in place, I can record starting at about 9pm. Once I quit my day job (that is based upon the amount of income I bring in from videos), I can record all day long. That will GREATLY increase the amount of content I can put out. That is also when I'll start being able to put out a video per week in other languages that complement C# like SQL, HTML, CSS, JavaScript, etc. My first priority will be C# but once I have more time, I can support developers more fully in the other areas as well.

    • @bmrreddy2002
      @bmrreddy2002 6 лет назад

      Tim ,If that's the route you wanna go, I honestly think you need to put out a lot of your content on Udemy and other sites and make them paid courses. Your explanation is just fantastic and you deserve to get paid for it!

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +2

      Well, I will be doing more paid courses in the near future (and long-term). I have a few at IAmTimCorey.com but I'll be adding a few more soon. I've looked at Udemy but they really take a lot from teachers (50% plus they set pricing so your $40 course might be sold for $10 without your say). I really don't want to go down that road. I'll stick with my own platform where I can charge a reasonable amount and get about 95% of the asking price.
      I appreciate the kind words.

    • @bmrreddy2002
      @bmrreddy2002 6 лет назад

      IAmTimCorey ah true! See I don't know what their cut is, but yes that's a lot. But you're a real good teacher and would do great doing this full time! Will take some time to get there for sure. Good luck ! :)

  • @ademineshat
    @ademineshat 5 лет назад

    I was busy watching your other Videos, but today was the Time, yay.
    I've been using a separate class like processor for every model like you said :) where i was doing queries with Dapper and Today was the day when I put them all in one place. I was allways feeling that I'm repeating my self, and I really was!
    Thank you very much Tim

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +2

      I'm glad you were able to figure that out and improve. Well done.

    • @ademineshat
      @ademineshat 5 лет назад

      But still a Tutorial with Generics and Dapper will be great :)

  • @jean-marcblanchet2270
    @jean-marcblanchet2270 3 года назад +1

    Well, thank you Tim for the great content you provide for free to us, the C# developers community. I have an old habit I took when learning C language, a long time ago when I was a student. I always put my checking code at the beginning of my methods, before any declaration or usage of variables and objects. So that I get rid of incorrect or incomplete values before going further, for instance by raising an exception or returning an error code. I don't know if it's a good practice, but I'm sure data is correct after that checking step.

  • @madhavmehendale7324
    @madhavmehendale7324 4 года назад +1

    This opened my mind to a lot of things that Ive seen on your other videos but which I did not fully appreciate - until now

  • @texaslinux
    @texaslinux 4 года назад

    I've been working with .NET, and primarily C#, since before it was even publicly available and I still learn great things from your videos. Thank you!

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      You are most welcome. Thanks for watching.

  • @jasper5016
    @jasper5016 5 лет назад

    You are the greatest instructor I have ever seen. You are just awesome.

  • @chukwumaesoga5171
    @chukwumaesoga5171 4 года назад

    I have always struggled to understand generics and how to use collections and this video just broke it down for me in the simplest way. You are awesome at how you approach topics and i jsut subscribed to you channel so i can learn more

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      Glad it was helpful! Thanks for the sub!

  • @jasonjames1849
    @jasonjames1849 3 года назад

    Excellent video, Generics have always been a bit confusing to me and it helps me best when there is a practical demo like in this video. So thanks for that

  • @drip888
    @drip888 3 года назад

    time 13:15
    the PopulateLists() takes up two argument, how can the stuff we added to that new argument people and logs in the function affect the actual variables people, logs in the Main(). is the function calling passing the value or adress of the value??

  • @dotnetmohan
    @dotnetmohan 6 лет назад +1

    Nice explanation of restriction part (where T : class etc). Am now clear understand . Thanks buddy.

  • @ASHOK_162
    @ASHOK_162 4 года назад

    36:00 For Example If I don't have to write T entry =new T(); in other any methods then I don't need to specify new() key word in method signature right.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      We are using T because we don't know the specific type. Pretend for a minute that T was PersonModel. See how that would look? Now remember that we are creating a generic method where we don't know what the type being passed in will be. We name that type T.

    • @ASHOK_162
      @ASHOK_162 4 года назад

      IAmTimCorey I’m asking about new() keyword where save method does not have

  • @zulhishamtan4308
    @zulhishamtan4308 4 года назад

    Yes, Generic is useful, it can reduce duplicate code. Thank you very much. Very precise explanation.

  • @longuinni
    @longuinni 6 лет назад +1

    Really nice. You make C# much easier to understand.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      That's the goal. I'm glad it is working.

    • @longuinni
      @longuinni 6 лет назад

      IAmTimCorey yes, it's working. It will be great if you make a mvvm series. I don't know why I can learn mvvm.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад +1

      I do have an add-on course to my C# Application from Start to Finish course where I replace the WinForm UI with WPF (using Caliburn Micro and MVVM) if you want to check that out: iamtimcorey.com/courses/tournament-tracker-wpf-user-interface/

    • @longuinni
      @longuinni 6 лет назад

      I don't know why I didn't see this course before! Thank you Tim!

  • @RootofEvilify
    @RootofEvilify 4 года назад

    Thank you Tim! I work at company where we use C# and MVVM pattern, I learned some new things from you. :)

  • @rosahartanto8055
    @rosahartanto8055 3 года назад

    thanks tim corey for the sharing, hopelly continue share for next videos

  • @TheIcecoldorange
    @TheIcecoldorange 4 года назад

    @ 50:14, line 11, couldn't you instead have "public static List LoadFromTextFile(string filePath, Type T) where T : class, new()"? if what I wrote is valid, what is the difference, if any, compared to your line 11?

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      You still need to declare the in the name. You wouldn't need to pass in the type when calling the method explicitly because the added parameter specified the type but then you are creating an extra parameter (extra overhead) for no extra benefit.

  • @ViktorTy
    @ViktorTy 4 года назад +1

    Hey Tim! I am a very big fan of your videos! Thank you for helping me learn C#!
    I was wondering if you plan to make a follow-up on generics and speak about how we can use generics and dependency inversion together as principles to make dynamic interfaces that we can reuse?
    I think it is a very interesting and challenging topic that most people would appreciate.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +3

      Added to the list, thanks.

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

    Wonderful content Tim. Kudos to you!

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

    Very helpful, using reflection in the code is interesting.

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

    Danke!

  • @martinsteegh160
    @martinsteegh160 3 года назад +1

    Hi Tim, I don't know if this is important, but in my csv-file every line is put into one Excel-cel instead of 3 as it is in your csv-files. Perhaps this is an ignorant question but do you know why this happens?

    • @tomthelestaff-iamtimcorey7597
      @tomthelestaff-iamtimcorey7597 3 года назад

      CSV stands for 'Comma-Separated Values', so do you have a comma between the items you want in separate cells? Just a place to start your investigation.

  • @dragonburger5676
    @dragonburger5676 3 года назад

    She glad I found this channel!! Thank you Tim!

  • @scottk5083
    @scottk5083 6 лет назад +1

    That you very much. Has really improved my understanding regarding this topic. You are an excellet teacher

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      Awesome! I'm glad you were able to increase your understanding of the topic.

  • @MrGegere
    @MrGegere 5 лет назад +2

    Heh, I needed 6 minutes of Your video to understand what I need.
    Truly great content.

  • @andrijapavlovic6322
    @andrijapavlovic6322 6 лет назад +1

    Best tutorials on C#! Keep going!

  • @zerosandones7547
    @zerosandones7547 3 года назад

    What is the shortcut key for this @23:46?

  • @fyisic
    @fyisic 3 года назад

    Great video and explanation. I have trouble learning a lot of advanced C# like this though. Even if i understand it i need to use it in practice multiple times to actually make it stick in my head. And when its things like this that has very rare use cases its very hard. You get a long way with the very basics of C#, and that can become a problem.

    • @IAmTimCorey
      @IAmTimCorey  3 года назад

      Practice is definitely important. The more you practice it, the more you will grasp it.

  • @luih7314
    @luih7314 5 лет назад +4

    You're my hero Timmy
    Such an emotional video, you killed off Sue Storm :)

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад +6

      It was a rough one, but don't forget, Sue is a comic book character. They never really die.

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

    nice teacher....can i do like a method wich takes a list or single object as and print whatever inside that list or object?

  • @mirogeorgiev7095
    @mirogeorgiev7095 4 года назад

    It was very helpful for me. Thank you Tim.

  • @sunpengjie4565
    @sunpengjie4565 3 года назад

    I have to say this is the best generic courses.

    • @IAmTimCorey
      @IAmTimCorey  3 года назад

      Thank you!

    • @sunpengjie4565
      @sunpengjie4565 3 года назад

      @@IAmTimCorey Just let you know I purchased your course today haha

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

    Great material, bravo Tim!

  • @alikinng8653
    @alikinng8653 5 лет назад

    This is excellent and simple tutorial on C# generics. Thank you for your efforts and sharing your precious knowledge.Thank you sir!!

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      You are most welcome. Thanks for watching.

  • @VinuP2023
    @VinuP2023 6 лет назад +3

    Tim, 12,114 views and 418 likes and "0" dislikes as on date, That speaks quality of this video. :)

  • @francogiulianopertile279
    @francogiulianopertile279 3 года назад

    Great explanation, greetings from Argentina

  • @dennisdoodlepants9614
    @dennisdoodlepants9614 3 года назад

    Hey i'm a little bit lost, at 11:37 you use a list of type Person, what does that mean and what does it do as usually in my program.cs file I only use List's of type int or string

  • @tomservo75
    @tomservo75 5 лет назад

    Quick question: Is using $"{var1}, {var2}" kind of the same thing as using String.Format?
    For example could you have used lines.Add(String.Format("{0},{1},{2}",p.FirstName, p.IsAlive, p.LastName)); ?
    Not sure why you would use one and not the other. Or is the former simply a more compact version of the latter?

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      It is a more compact, easier-to-read version. That's really the only difference in terms of performance.

  • @yuriymayyagruzglin1812
    @yuriymayyagruzglin1812 5 лет назад

    As always - clear, concise, great. Thank you Tim!

  • @ericsmith6429
    @ericsmith6429 5 лет назад

    What if you want to set the class to the generic method dynamically if you have a string of the name of the class... something like
    Type t = Type.getType("aClass");
    SomeMethode(valueA,valueB);
    Haven't been able to get something like this to work.

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      You would need to use reflection, which is expensive. You can do it and there are reasons to do it but I would look first to see if you can do it a different way.

    • @ericsmith6429
      @ericsmith6429 5 лет назад

      @@IAmTimCorey it's actually for a design element only used by me for saving items into a json string that players will never use... so figured it would be appectable.. any examples you can point me towards?

  • @madChileRiver
    @madChileRiver 4 года назад

    Another great video clearly explaining an area that is often misunderstood!

  • @alexanderspiegel6747
    @alexanderspiegel6747 5 лет назад +13

    Here is my “like”, Tim. Thanks for the great lesson.

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      You are most welcome. Thanks for watching.

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

    Good job! I appreciate you posting your videos.

  • @willamsreis9715
    @willamsreis9715 4 года назад

    Great lesson, Tim. You've done a great jog teaching us how to handle with C# technology, Thank you so much.

  • @prubenheeren707
    @prubenheeren707 4 года назад

    Your videos are insanely good. Love it.

  • @nelsonluisfreire8969
    @nelsonluisfreire8969 4 года назад

    Great video, and correct pace

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

    Very helpful, thank you.

  • @sonorityscape
    @sonorityscape 3 года назад

    In the load LoadTextFromFile function The that you pass in is a string, but then you say "Where T : class, new()". Wouldn't that "Where" statement require you to pass in something like a Person instance or LogEntry instance rather than a string?

  • @carstenberggreen7509
    @carstenberggreen7509 3 года назад +1

    Tak!

    • @carstenberggreen7509
      @carstenberggreen7509 3 года назад

      Simple and usefull example from you. Elegantly touching Generics. Good video! Wanna show my support and hope that others will follow my example! Brilliant work Tim!

    • @IAmTimCorey
      @IAmTimCorey  3 года назад

      Thank you!

  • @traderviajero
    @traderviajero 4 года назад

    Great explanation, thanks!
    I have a doubt when you are talking about Reflection 00:37:17.
    I want to use reflection to map a DbDataReader to an entity class every time I execute a stored procedure (I would use this quite often). Would this be bad for my app performance? I don't find it very clear when you say that it's very expensive.
    Thanks a million for all your help. Regards!

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      Yes, this would probably be bad for your application’s performance. Reflection is slow. Try it out and benchmark how fast it is.

  • @lukenukem8028
    @lukenukem8028 4 года назад

    [49:00] Why is your Person and LogEntry dark in color? I never get dark ones.

    • @lukenukem8028
      @lukenukem8028 4 года назад

      In the Load function, it is not darkened. I've never seen T's darkened in generics.

    • @IAmTimCorey
      @IAmTimCorey  4 года назад

      That's just the dark theme in Visual Studio doing that. It darkens them when they are classes.

    • @lukenukem8028
      @lukenukem8028 4 года назад

      I thought that, but it's not consistent on your code.
      On the same screen, the same class is not dark.

  • @ec0321
    @ec0321 4 года назад

    Thanks Tim for explaining the concept of Generics in simple terms. You could have also covered the complexity analysis in more detail while discussing the applied reflections. But You did explain it a little bit in terms of time I guess...

    • @IAmTimCorey
      @IAmTimCorey  4 года назад +1

      I have constant thoughts on how to improve every video. Part of that led me to make this video on balancing that desire for perfection - ruclips.net/video/b5TspWBQkMk/видео.html

  • @dansolarta8937
    @dansolarta8937 6 лет назад +1

    makes it easier to understand generics than most books or bloggs offer.

    • @IAmTimCorey
      @IAmTimCorey  6 лет назад

      That is high praise. Thank you.

  • @solvedplus858
    @solvedplus858 4 года назад

    very very awesome , you are so great, yesterday i was creating method to write and read xml files and i couldn't make them generic, know i now why and thanks to you
    many many thanks

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

    Great job!

  • @ahmer9800
    @ahmer9800 5 лет назад

    very glad i found this video. i've been trying to sort out template interfaces for days!!!

    • @IAmTimCorey
      @IAmTimCorey  5 лет назад

      I'm glad you got value out of this video.