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



Have you ever used a List of T and wondered what the T meant? Or maybe you heard the term generics but you did not really …

41 Comments

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

  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?

  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

  4. Hey Tim my man .. I’m from Allentown I love Krispy Kreme from Scranton. Back to the topic, Do you have any course with regards to generic constraints? I would love to buy.

  5. 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??

  6. 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 🙂

  7. 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.

  8. When I apply the Save method on my computer, it saves all records into a single column in the csv file, does anyone has an idea?

  9. I like your videos and explanations; however, this one has way too much going on just to explain generics and how to use them properly. All of the filler information causes a loss of concentration on the main subject. Reflection and creating .csv files etc… could be a video on its own and just stick with generics and why and how to use them. Just make it as simple as humanly possible to understand its usage.

  10. Great tutorial. You could possibly optimise the code in the SaveToTextFile<T> method by creating another method that loops through the columns and build the line without the trailing comma, as this code is duplicated.

  11. Love your videos, even when I know and understand a topic I do learn something from you! Great teaching style and very informative. Strange question that always confused me: any idea why the term was called generics as in reality they are specific. To me the original collections were generic as they could accept any object, while "generics" are specific to a type, not generic…

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

  13. Hi Tim. Recently found you and even being an established coder, I feel I've learnt lots from you over the last week.

    Quick question. I too have used Generics for SQL connectivity to scale down a helper class I had for creating and reading parameter in SQL queries, going from a method for each type to generic methods to encompass all of them. Thinking about your discussion in this video about doing it also for the SQL connectivity portion, would Generics work for a "void" method declaration as well as where a return type is needed? My thought on this without experimenting of course, is that you'd have 2 methods, one where there is a return type and then another where there isn't? Would that be the case?

  14. This is very useful, just to let you know I oped in for the source code and haven't received an email so it might not be working.

  15. Other than the isAlive status this is a great guide lmao for someone who has experience trauma with death i tried my best watching this guide. But i guess i'm not brave enough to finish it xd.

  16. 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.

  17. is there a way to filter what T is as an object? as in when using the method i want T to only accept objects that are numbers, such as a double, decimal, int, etc.., or do i have to make many methods with the objects types that i allow?

  18. 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….

  19. 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

  20. In the load LoadTextFromFile function The <T> 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?

Leave a Reply

© 2023 53GB