C# Essentials: Linq for Lists - Sorting, Filtering, and Aggregating Lists Easily

Sdílet
Vložit
  • čas přidán 22. 05. 2024
  • Having a List for an object is a fairly common occurrence in C#. In fact, most data access systems end with having the data in a List. This video will help you see how to sort, filter, and operate on lists easily and powerfully.
    You will see examples both in a Console application and in a Windows Forms application. This practical example dives right into the most important parts of Linq to get you up and running in minutes.
    Get the Starter Code: leadmagnets.app/?Resource=Lin...
    Mailing List: signup.iamtimcorey.com/
    0:00 - Intro
    0:43 - demo app walkthrough
    3:56 - for each item in the list, do this - foreach loop.
    5:24 - sorting the list of items by item property: OrderBy
    8:42 - sort the list descending: OrderByDescending
    9:29 - sort the list by more than one parameter: ...ThenBy
    11:18 - filter the list: Where(bool true)
    15:14 - Sum of the countable property of objects in the list
    16:20 - combining list methods: Where and Sum
    18:29 - using Linq in applications - WinForm app walk-through: (data binding, events)
    22:55 - Implementing Linq

Komentáře • 317

  • @adoreyourpain
    @adoreyourpain Před 2 lety +13

    6:59 your explanation of lambda expression just blew my mind, I could not wrap my head around it, and in a completely unrelated video, you explained it in 15 seconds. Wow, thank you!

  • @andrewcrawfordacr2529
    @andrewcrawfordacr2529 Před 6 lety +18

    You have great insights about how to teach, level of detail and pace. Thanks.

    • @IAmTimCorey
      @IAmTimCorey  Před 6 lety +3

      Thanks for the kind words. I'm glad you enjoy my style of teaching.

  • @Contractor48
    @Contractor48 Před 3 lety +12

    Best c# channel hands down. The best part is you do write the code on the fly rather than using clipboard. I really admire that about your channel.

  • @anasabubakar4125
    @anasabubakar4125 Před 7 lety +7

    You are very helpful to many new developers. Tutorials like this are very rare. Thank you very very much, you are AWESOME

    • @IAmTimCorey
      @IAmTimCorey  Před 7 lety +5

      Thanks for the kind words. I'm glad you found my videos useful.

  • @torrvic1156
    @torrvic1156 Před 9 měsíci +1

    Such a short and sweet video which explained to me the whole logic of Linq and what this fancy x is and what this arrow meant. I had no idea as how to use Linq before watching your video. Not only that but I understood lambda (funky “arrow”) and your comparison to foreach loop was such a great idea! Thank you so much, Tim! This old video is like a refined and exquisite old wine in the cellar.

  • @georgekaragiorgos
    @georgekaragiorgos Před 2 lety +2

    A great introduction to Linq that explains the concepts with very simple examples and allows you to explore in depth on your own. Many thanks, Tim! You are great as in all of your tutorials that I have watched till now! I really like your teaching style and your pace...

    • @IAmTimCorey
      @IAmTimCorey  Před 2 lety +1

      You are most welcome. Thanks for watching.

  • @aungyethu9743
    @aungyethu9743 Před 4 lety +2

    Following along, one of a kind tutorial for me. It really reflects the real world situation. Thank you, Tim.

    • @IAmTimCorey
      @IAmTimCorey  Před 4 lety

      You are most welcome. Thanks for watching.

  • @drambooi7169
    @drambooi7169 Před 2 lety +2

    This was excellent. Thinking of the expression as short-hand for a 'foreach' statement finally unlocked understanding these expressions for me. Thank you!

  • @alainleclerc4523
    @alainleclerc4523 Před 4 lety +3

    simply: you are the best!! so clear, so nice, so simple! thank you very much tim for all your efforts for all of us. you are so kind!! be blessed!!

  • @calogiga
    @calogiga Před 5 lety

    Many thanks for this tutorial. This is the first clear tutorial about Linq that I can understand on CZcams. Very simple and well explained. Muchas gracias !

  • @emaus8344
    @emaus8344 Před 2 lety +4

    Tim's channel is the best reference resource for c#!

  • @jyotirmoymaschatak2599
    @jyotirmoymaschatak2599 Před 2 lety +4

    Nobody does this better, You are awesome Tim! Great explanation!

  • @Robotron2084Guide
    @Robotron2084Guide Před 6 měsíci +2

    Your content is SOOOO well done for thinking logically through the building blocks of these abstract topics. Thanks again! Its great that these years old lessons are still relevant and work as shown in current Visual Studio, too. Hashtag magic! Cheers.

  • @josephddl883
    @josephddl883 Před 6 lety +1

    I enjoyed it and will be watching more of your videos. I'm currently learning the basic of C# and your videos have such good explanation and easy to understand. Thank you and hopefully you'll keep uploading.

    • @IAmTimCorey
      @IAmTimCorey  Před 6 lety

      I'm glad you are learning a lot. Keep it up.

  • @Silanar
    @Silanar Před 4 lety +3

    This helped me alot!
    Im still new in C# and still learning to work with Lists.
    Thanks for the teaching

  • @yperman1
    @yperman1 Před 8 měsíci +2

    I have told you before. You are a great teacher thank you for your work and knowledge.

  • @mau_lopez
    @mau_lopez Před 6 lety +1

    Excellent tutorial once again ! I really like Tim's explanations.

  • @ronie635
    @ronie635 Před rokem

    Wow, after days of scouring the web and looking at tutorials, this really nailed it! Thanks for the content, it really helped me in my school-project :)

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      Excellent! I’m glad it was helpful.

  • @viniciusmorgado9722
    @viniciusmorgado9722 Před rokem +2

    This video help me a lot in my internship, thanks Tim!

  • @joji2910
    @joji2910 Před 5 lety +1

    One of the best tutorial I've ever seen. Thanks :)

    • @IAmTimCorey
      @IAmTimCorey  Před 5 lety

      You are most welcome. Thanks for watching.

  • @yulimusj
    @yulimusj Před 2 lety +1

    Thank you Tim. Very clear and informative video

  • @hajarelmajid6842
    @hajarelmajid6842 Před 3 lety +1

    I've learnt so many things. Thank you Tim!

  • @MaddCoder
    @MaddCoder Před 5 lety

    Another awesome video by Tim. Thank you so much.

    • @IAmTimCorey
      @IAmTimCorey  Před 5 lety

      You are most welcome. Thanks for watching.

  • @TheSeen720
    @TheSeen720 Před 3 lety +4

    Finally an explanation with human language. I write 20 lines of code for a problem then I see one person write
    return a.Where(n => !b.Contains(n)).ToArray(); and get the same result.

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety +3

      More lines isn't a bad thing. Do what is most easily readable.

    • @hatrer2244
      @hatrer2244 Před 3 lety

      @@IAmTimCorey Amen!

  • @bryanwhatley
    @bryanwhatley Před 7 lety

    Good stuff, very well explained! Thanks!

  • @louissasha
    @louissasha Před 11 měsíci +1

    Great tutorial, thank you for taking the time to explain!!!

  • @mohamedhussein9679
    @mohamedhussein9679 Před 2 lety +3

    Thanks Tim, it helped me a lot!!

  • @ebman889
    @ebman889 Před 6 lety +1

    You are awesome! Thanks a lot, couldn't be simpler than this.

  • @becreativewithrucha471

    Thanks for sharing really useful videos.You are a very good teacher.

    • @IAmTimCorey
      @IAmTimCorey  Před 4 lety

      You are most welcome. Thanks for watching.

  • @sakarikorpela1269
    @sakarikorpela1269 Před 2 lety

    Excellent, thank you Tim!

  • @Zamoksva
    @Zamoksva Před rokem

    Thank you so much for this, really well explained!

  • @kylekeenan3485
    @kylekeenan3485 Před 2 lety

    Thanks so much for this - I learned nothing, however this was a good thing as it affirms that I know what I am doing and on the right track as a Developer.

  • @reezuanrahim6646
    @reezuanrahim6646 Před 3 lety +1

    Clarity at last... thank you.

  • @damienk777
    @damienk777 Před 7 lety

    Thanks Tim, it's a really helpful video.

  • @RalfsBalodis
    @RalfsBalodis Před 3 lety +5

    0:43 - demo app walk through
    3:56 - for each item in the list, do this - foreach loop.
    5:24 - sorting the list of items by item property: OrderBy
    8:42 - sort the list descending: OrderByDescending
    9:29 - sort the list by more than one parameter: ...ThenBy
    11:18 - filter the list: Where(bool true)
    15:14 - Sum of countable property of objects in the list
    16:20 - combining list methods: Where and Sum
    18:29 - using Linq in applications - WinForm app walk-through: (data binding, events)
    22:55 - Implementing Linq

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety +1

      Thanks! I added it to the description.

  • @andresndergaard1712
    @andresndergaard1712 Před 5 lety

    This helped me out! Thank you, sir!

  • @ntt212
    @ntt212 Před 4 lety

    Very nice tutorial. Thanks

  • @attilaszeidl3041
    @attilaszeidl3041 Před 4 lety

    This helped me a lot! Thank you so much

  • @jesuscampos2587
    @jesuscampos2587 Před rokem

    It was another helpful video, keep doing videos like this, congratulations

  • @bhavanpreethamch7062
    @bhavanpreethamch7062 Před rokem

    Good Introduction..Thank You

  • @edeal7481
    @edeal7481 Před 3 lety +1

    that really helped! thanks man!

  • @ZenOfKursat
    @ZenOfKursat Před 6 lety +1

    awesome tutor. appriciated.

  • @juankmilisimo
    @juankmilisimo Před rokem +5

    ¡Gracias!

  • @AnasJayyusi
    @AnasJayyusi Před 5 lety +1

    You are Brilliant Bro

  • @amannan-123
    @amannan-123 Před 3 lety +2

    finally someone who is using lambda expressions... love this video

  • @iancarr3923
    @iancarr3923 Před 5 lety

    Great video, thanks.

  • @rockymarquiss8327
    @rockymarquiss8327 Před rokem +1

    Tim,
    I always enjoy your videos. I do have a question for you. Though I've been programming since 1981, I'm a newbie to C#. I am building a list of legal descriptions and I see two different ways to do it, but I don't know which is most appropriate or if there's a third option that may be better - or if it's simply a choice of style. The way that I implemented it as follows:
    foreach (var legal in legals)
    {
    LegalLocationModel LegalLocation = new();
    LegalLocation.AccountNo = LegalDesc.AccountNo;
    LegalLocation.DetailID = maxDtl++;
    LegalLocation.QTRQTR = legal;
    LegalLocation.Section = "";
    LegalLocation.TownShip = "";
    LegalLocation.Range = "";
    LegalLocations.Add(LegalLocation);
    }
    Alternatively
    foreach (var legal in legals)
    {
    LegalLocations.Add(new LegalLocationModel { AccountNo = LegalDesc.AccountNo, DetailID = maxDtl, QTRQTR = legal, Section = "", TownShip = "", Range = "" });
    maxDtl++;
    }
    Is there a reason that one of these choices is a better choice or is there a third option that may be better than either of them?
    Thanks for your insight,
    Rocky

  • @carlagoncalves531
    @carlagoncalves531 Před 5 lety +2

    Just discovered your channel A.M.A.Z.I.N.G

    • @IAmTimCorey
      @IAmTimCorey  Před 5 lety

      Welcome aboard! I'm glad you are enjoying the content.

  • @pratikranchhod889
    @pratikranchhod889 Před 6 lety +1

    Very nice explanation Sir :-)

  • @cyberla
    @cyberla Před 6 lety +5

    This guy is the best :-)

  • @IndritVaka
    @IndritVaka Před 2 lety +2

    Thanks a lot. It was really helpful.

  • @riri_007_
    @riri_007_ Před rokem +2

    Hello sir we need an updated video of LINQ both method syntax and query syntax. Great video indeed.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @iraqiroyale4483
    @iraqiroyale4483 Před 2 lety +2

    You are Amazing ❤

    • @IAmTimCorey
      @IAmTimCorey  Před 2 lety

      Thanks!

    • @iraqiroyale4483
      @iraqiroyale4483 Před 2 lety

      @@IAmTimCorey i always See those Pro Programmers Solving Problems in one line using the Where or Orderby and i solve it with 10 lines😆 Thanks for teaching me how to do it ❤

  • @rodrigomoro8047
    @rodrigomoro8047 Před rokem

    Thanks for the video!
    One question:
    Whats the difference between the following two approachs?
    List listOfIntegers = new List{1,2,3,4,10,20,30,40,50};
    var smallNumbersApproach1 = from element in listOfIntegers
    where element >= 10
    select element;
    smallNumbersApproach1 = smallNumbersApproach1.ToList();
    var smallNumbersApproach2 = listOfIntegers.Where(x => x >= 10).ToList();

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +2

      The second approach has less allocations and is therefore more efficient.

  • @jonatancordoba7984
    @jonatancordoba7984 Před 3 lety

    26:07 I've seen enough of your videos to point out that that copy/paste can be refactored, haha. Love your content.

  • @T_U_F
    @T_U_F Před 2 lety

    Excellent sir, we want more and more videos

  • @edechelcambarihan5544
    @edechelcambarihan5544 Před rokem +2

    The funky symbol is a lambda expression. Overall, the tutorial is not bad and I like showing the Form UI and LINQ Library.

  • @SpaceIT7
    @SpaceIT7 Před 7 lety

    Hi Tim, Please, whenever you have time would you consider data binding and lists. All data binding options that are available. Thank you in advance.

  • @christianjamesguevarra6257

    Thanks Tim, very clear and very helpful. If you have time, would you do a tutorial on Linq Expression trees and/or implementing Repository pattern using ADO.NET or Dapper ORM because most of the tutorials on the web teaches Repository pattern using EF. Thanks in advance!

  • @fadisy4045
    @fadisy4045 Před 5 lety

    thank you so much
    this better video to learn linq
    we need to more video

  • @chris5947
    @chris5947 Před rokem

    Thank you!

  • @risechess7114
    @risechess7114 Před 5 měsíci

    thanks very informative

  • @misterdecaro
    @misterdecaro Před 5 lety

    Tim, firstly thank you for all of your hard work! I have watched many of your videos and will be trying to catch them all eventually. I enjoy your teaching style and I love the weekly challenges! I've only done two so far but plan to try more of those also.
    For my benefit and hopefully others, can you reply with what software you are using so that I can follow along using the same software. You may have mentioned it in your videos but I want to make sure I'm using the exact same if I can. (Currently using a much older .Net installation and command line editor and compiler).
    Thank you :)

    • @IAmTimCorey
      @IAmTimCorey  Před 5 lety

      I use Visual Studio 2017 Enterprise Edition (but Community Edition, which is free, is almost the same). When VS2019 comes out, I will upgrade to it.

  • @TezzRah
    @TezzRah Před 6 lety

    Thanks for clearing that up, i was looking at exercise solutions for c# homework thinking i must have missed something.... nope its LINQ syntax! doh! lol

  • @InsEngineered
    @InsEngineered Před 4 lety

    Hi. Thanks a lot. I do appreciate your tutorial series. Will you be able to make a similar tutorial for caliburn micro? the lists using 'BindableCollection' is not well documented.

    • @IAmTimCorey
      @IAmTimCorey  Před 4 lety

      The TimCo Retail Manager series uses WPF with Caliburn Micro. I believe it will cover what you are looking for. I also have a WPF playlist that covers Caliburn Micro quite a bit.

  • @muttBunch
    @muttBunch Před 3 lety +1

    Tim, thank you so much for this. Even though this is a much older video, I'll say it again, with your explanation of what each is doing, I absolutely love. If you get a chance to see this maybe you might be able to tell me why my ".Distinct()" isn't working?

    • @muttBunch
      @muttBunch Před 3 lety

      Better yet, what I'm trying to do is, I have a list from AD that's showing ("Administrator" with a LastLogon "7/27/2020 12:19:26 AM" from "DC01" )and another ("Administrator" with a LastLogon "8/4/2020 1:10:50 PM" from "DC02").
      I'm trying to have the list only display ONE "Administrator" once but only show the "Administrator" with the most recent logon date of "8/4/2020 1:10:50 PM". Kind of need some help with this.
      I have C# down pretty good but the trickiness of ASP.net is killing me but finally got my "returns ..." in the right spot after a ton of nested foreach loops. - thanks

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety +1

      It sounds like you want to do a GroupBy on Administrator and then do a Last on the date.

    • @muttBunch
      @muttBunch Před 3 lety

      @@IAmTimCorey , thank you for the quick reply. I greatly appreciate it. I'll check that out and reply back when successful :)

  • @hamzah1738
    @hamzah1738 Před 4 lety +2

    Hi Tim , I really enjoyed learning linq query in your video, I have a question out of the context, why you declared the method LoadSamplData() as a static method?

    • @IAmTimCorey
      @IAmTimCorey  Před 4 lety

      Because it wasn't storing any information, so it did not need to be instantiated.

    • @nldxl
      @nldxl Před 4 lety

      You can use the class methods without creating new instance of the Class.

    • @IAmTimCorey
      @IAmTimCorey  Před 4 lety +1

      Correct - instantiation isn't necessary because we aren't storing data in the class, which makes calling it faster.

  • @dani4u87
    @dani4u87 Před 7 lety

    Thanks Tim, very useful! Never really used Linq for Lists yet, cause to me it looked somewhat abstract when i see those "massive" statements people do with Entity Framework.
    I have a suggestion: What about a Video to get through the "advanced basics" in OOP in relation with WPF and/or concepts like MVC or MVVM. I'm actually a (certified)software developer, but i'm still in a pretty early stage, working on my skills about those things atm, especially with WPF. The problem about all that is, there isn't a real explanation HOW and WHY a developer should use MVC or MVVM and how to get started and what should be kept in mind.
    The thing is: You got it, you actually explain things like they are in a very easy to understand way.
    Oh, and I'm actually having the problem "navigating" or... associating through a bunch of different lists, keeping objects they each other relate on (companies have jobs f.e., the class company has a property named Jobs from type List, the class Job has a property company from type Company) - So i want to do a simple if statement, if the company selected has still job objects in the other list, there should be an error, otherwise, it can be marked to delete the entry.
    if (companyList.ElementAt(lvCompanies.SelectedIndex).Jobs != null)
    The Job property IS NULL at the time of execution but it jumps in that if statement anyways, it probably is a really dumb bug but i still didn't find the problem.
    (Oh no, I'm sorry for that long comment)

    • @dani4u87
      @dani4u87 Před 7 lety

      Thanks for the feedback. Where do you upload the full courses? I will definately look caliburn.micro up, but do i really need a framework to begin with MV*? Sometimes it's better to "start" by scratch, like with your log4net tutorial :)
      The problem i had was definately more of a logical/design issue in the backend logic, cause the way it was made more of a mess than anything else. Now i restructured everything and I'm only serializing the companylist atm. When i deserialize i go through two for loops cause of the nested List and strip the joblist out from there. works much more cleaner.
      Thanks for the suggestion how you would do it!
      Well, WPF is really simple to understand in the first look, but those curly braces statements with bindings etc. are definately one of the difficultest things to do, cause of the missing intellisense.

  • @ImproveMyself12
    @ImproveMyself12 Před 4 měsíci

    Thanks a lot, i knew that but is a good idea remember one we have time.

  • @user-fh3sr2lr2x
    @user-fh3sr2lr2x Před 3 lety

    Thanks soso much

  • @toreshimada
    @toreshimada Před rokem +7

    This video was great because it taught me how to programatically throw CVs in the trash if they have less than 9 years of work experience.
    Thanks Corey!

  • @michaeleichner7522
    @michaeleichner7522 Před 5 lety

    Another great video.
    I do have one question. I always retrieve data via stored procedures. In general my assumption is that for performance reasons that filtering the data is always best done in the stored procedure vs. LINQ so that I’m not passing extra data back to my lists. Does the same hold true for sorting? Am I better off sorting my data in my stored procedures or am I better off returning un sorted data to my lists and having LINQ sort them? My question only relates to performance.
    Thanks

    • @IAmTimCorey
      @IAmTimCorey  Před 5 lety +2

      My philosophy is to use each tool for what they do best. SQL stores, processes, filters, and sorts data as its primary job. Therefore, whenever possible I let SQL do its thing. C# manipulates data in certain ways better than SQL does and it. C# also is better at working with the data once it is loaded into C#. So, I do my initial filtering and sorting in SQL. Then, if I need to further refine things or do any refinement later, I do it in C#.

  • @Jansa372
    @Jansa372 Před 2 lety +2

    Thanks for the great explanation you really make things easy to understand especially for beginners like me. I just finished watching the dapper video you made (How to connect C# to SQL (the easy way)) and now this leaves me with a few questions. So if dapper can execute SQL queries why is LINQ needed? For example, here you used order by but can't that be executed with an SQL query using Dapper? In what ways are LINQ and Dapper similar / different?
    I'm not sure if I'm making any sense to be honest. Would appreciate if you could explain this to me please. Thanks

    • @IAmTimCorey
      @IAmTimCorey  Před 2 lety +3

      LINQ is used to perform queries on sets of objects in C#. So, let's say you load all of the users from the database. Then, you could filter to only the active users inside of C# for one list and all of the inactive users for another list. You would only need to perform one query of SQL but you could use LINQ to pull out different sets of data out of that one superset.

    • @Jansa372
      @Jansa372 Před 2 lety

      @@IAmTimCorey It makes much more sense now. Thanks for taking the time to reply, much appreciated.

  • @robertminardi4268
    @robertminardi4268 Před 7 lety

    Hey Tim, great content. Is there a place we can download the structure for this demo?

  • @minhthai9521
    @minhthai9521 Před rokem

    Hay lắm anh trai. Thank kiu anh

  • @mohabbatazim3538
    @mohabbatazim3538 Před 3 lety

    Thanks.

  • @muamberkhan3374
    @muamberkhan3374 Před 3 lety +1

    Hello sir, i really appreciate what you do and how you do it! Salute to you, sir. I am a junior developer and building mainly desktop apps. i need to learn "How to manage Many to many " relationship data.
    and how to get data from such table............... Please make such a video...

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety +1

      I will add it to the list. Thanks for the suggestion.

    • @fleurarkesteijn5122
      @fleurarkesteijn5122 Před 3 lety

      I second this! Especially implementing good views for this, and actions that work cascadingly with linked classes (fe displaying, editing or deleting class student with courses (not to be removed) and grades). Scaffolding always excludes these groups but in an application i often want to include them.

    • @muamberkhan3374
      @muamberkhan3374 Před 3 lety

      @@IAmTimCorey thank you

  • @jahwni
    @jahwni Před 2 lety +1

    So what is it in C# when there is .WhereEquals and .Select etc?? Can do it on a QueryObject, but is that LINQ as well? Trying to find out what to learn, this video didn't seem to cover that stuff. Anyone got any suggestions? Thanks!

  • @iAndrewMontanai
    @iAndrewMontanai Před 6 lety

    so useful

  • @sivadotn
    @sivadotn Před 3 lety +2

    Hi Corey, the content is spot on please share the code repository url.

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety +1

      I link to the code in the description of my videos. If there is no link, I don't have the source code anymore. Sorry.

  • @JoshyHJoshy
    @JoshyHJoshy Před 7 lety

    I tried to replicate this application, so that I could run it myself. I referenced the class library and also added the directive the way you had taught in the ConsignmentShop tutorial. But for some reason in my Dashboard class, the "using LinqLibrary" directive would not be recognized. There was an auto suggestion to fix it which replaced the "using LinqLibrary" with "using ConsoleUI" and that resolved it, but I don't understand why?

  • @pako_tube6898
    @pako_tube6898 Před rokem +1

    Thak you very much Sir, I have a problem, I want to know how to pass an object (included in ListBox) to another form after select the item.

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +2

      Request that object in the form's constructor.

  • @waynemv
    @waynemv Před 6 lety +1

    This is a great video. Thanks.
    I watched it because I wasn't sure what LINQ actually was. I had the misconception that somehow LINQ was more complicated than regular C# and expected LINQ to have a unique syntax of its own. Now I realize I'd seen examples like this before without realizing it was using LINQ!
    I was, though, a little surprised you copied that line instead of immediately refactoring the code to avoid the duplication. Is DRY ("Don't Repeat Yourself") a valuable practice to follow?

    • @IAmTimCorey
      @IAmTimCorey  Před 6 lety +2

      So you can use the more complicated "SQL-like" LINQ statements (from...where...select...) but a lot is built into the lists, which makes it really easy. As for not refactoring to keep something DRY, this is a demo of LINQ and while I try to follow best practices and show those off while I'm doing other things, I have to maintain a balance in a demo. If I show off refactoring to keep something DRY, will it be beneficial to the viewer and does that benefit outweigh the extra time and complexity it will incur. In this case I decided to reduce the complexity and time to focus just on LINQ.

    • @waynemv
      @waynemv Před 6 lety

      Fair enough.

  • @gsxMac24
    @gsxMac24 Před 3 lety

    Is it possible to do this with dapper?

  • @chrislbaird
    @chrislbaird Před rokem +2

    Any chance on getting an updated video on this topic?

    • @IAmTimCorey
      @IAmTimCorey  Před rokem +1

      Thanks for the suggestion. Please add it to the list on the suggestion site so others can vote on it as well: suggestions.iamtimcorey.com/

  • @hungnguyencanh5013
    @hungnguyencanh5013 Před 4 lety

    Thank you for your lesson. Very useful!
    But 1 question: How to return the original list after filter by linQ?

    • @IAmTimCorey
      @IAmTimCorey  Před 4 lety +1

      With a List, you return a new List. If you want to sort an existing list, you would need to use a different list type.

    • @pascalmariany
      @pascalmariany Před 3 lety

      IAmTimCorey So if I want to call a list from another class that’s inside a method inside Program.cs I should put that list again in a new list? Or how do I get the contents of the list inside memory? In the other class I use CSV helper to read a CSV file and put the contents into a list. This list I want to call inside Program.cs to load default users.

  • @RalfsBalodis
    @RalfsBalodis Před 3 lety

    Hello Tim.
    I find myself very often in situation when I want to use foreach loop and then do something with the item form that list (collection) Lets say List. As you know, you can't really do that.
    I find that I have to make copies of lists and do all kind s of crazy workarounds that does not feel very efficient.
    Could you suggest best practice here?

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety

      When looping over objects, you cannot modify the list without causing issues. So, you need to look at what you are really trying to do. There is usually a different way to accomplish the same thing. Maybe use a LINQ query to transform the list (filtering with a where clause). You are on the right track with your question for sure. Now you just need to keep poking at it until you come up with something better. For now, though, it does work which is a good first step.

  • @alinawaz4034
    @alinawaz4034 Před 6 lety +1

    too helpfull!

  • @tresaidh3y90
    @tresaidh3y90 Před 2 lety +1

    I know this may be a silly question. Again thank for another great lesson Tim. But your Program.cs file within your FormUI console is that file blank or does it have any relative code? I was following you along on Visual Studio Code and was coming across a debugging error where it said my Program.cs file within the FormUI console had no static Main method. (Which is because I was displaying my output within the ConsoleUI. I had to delete the FormUI console app template entirely to run my program.
    Here is my real question: Would my project have run if I created a Dashboard.cs[design] file and followed along with that portion of the video? Leaving the Program.cs file blank?
    Again thank you for another great video.
    The answer: Program.cs is where you initialized the form.

    • @tresaidh3y90
      @tresaidh3y90 Před 2 lety

      P.S. Can we get a video on creating web applications within Visual Studio Code vs Visual Studio 2022. Your video on coding C# within Visual Studio Code was superb!

  • @sasanapurikrishnarao
    @sasanapurikrishnarao Před 3 lety +2

    ListManager class was static one when i'm trying to access that class facing protection level error

    • @mandy1339
      @mandy1339 Před 2 lety

      Probably your Person class is internal instead of public. Make them all public to follow along this demo.

  • @yasard1345
    @yasard1345 Před 3 lety

    How did you make that year picker (Basically a number picker) in the form application. I couldn't find such a control ;)

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety

      Not sure which one I used, but this would probably work: github.com/alex-titarenko/wpfcontrols

  • @bryan69087
    @bryan69087 Před 7 lety

    There has to be a better way to update bindings other than having to remember to duplicate the line of linq code, right? Thanks for the videos, very helpful!

    • @bryan69087
      @bryan69087 Před 7 lety

      Thanks for the reply Tim. I'd be interested to see the video of the bindinglist, if only for clarity and exploration.

  • @agw1549
    @agw1549 Před 5 lety

    Thx sir

  • @hamzayoussef1129
    @hamzayoussef1129 Před 6 lety +3

    Is it a good idea to get the data from the database at the first time, then we filter it just by using lists (LINQ) instead of getting the filtered data from the database directly?

    • @IAmTimCorey
      @IAmTimCorey  Před 6 lety +3

      It depends on the situation. Typically though, the database is best at handling data, including filtering and sorting. That is what it is designed to do. A C# application will never be as efficient at SQL at filtering data. However, that assumes one client and one SQL Server. If you have 100,000 clients to one underpowered SQL Server, you might find that the overall performance is better if you bring the raw data down to the clients first. In general, though, that isn't the case. I default to letting SQL do data and then, once I have the data, I do any further refinements to it if I need to (that the initial call didn't anticipate).

  • @sharayus6832
    @sharayus6832 Před 3 lety

    How can I sort List by its value, that is by the size/count of the List in the KeyValuePair?

    • @IAmTimCorey
      @IAmTimCorey  Před 3 lety +1

      You can do it. Take it one step at a time. Make a query for just the KVP (forget that it is in a list for a minute). Then, once you have figured out that query, figure out how to do the same thing inside of a list.

    • @sharayus6832
      @sharayus6832 Před 3 lety

      @@IAmTimCorey Thank you very much sir.

  • @danielm1459
    @danielm1459 Před 2 lety

    In UpdateBinding you used x.YearsExperience >=5, which is hardcoded, how come your list is still updated based on your selection?

    • @IAmTimCorey
      @IAmTimCorey  Před 2 lety +2

      The number of years of experience is hard-coded, but which items meet that criterion changes as we change their YearsExperience value. So, when I change Sue's experience from 1 year (not showing in the list) to 15 years, she shows up on the list because she has more than 5 years of experience now.

  • @ABCshake
    @ABCshake Před 3 lety

    Do you a git reposiity for the ConsoleUI, FormUI and LinqLibrary code?

  • @destinyamanze8648
    @destinyamanze8648 Před 5 lety

    Please i cant find how to get the c# fundamentals, i need help on that, i have searched and still cant find videos related to that, thanks.

    • @IAmTimCorey
      @IAmTimCorey  Před 5 lety +1

      Here you go: www.iamtimcorey.com/blog/49797/how-to-learn-csharp-well

  • @azizbekibnhamid642
    @azizbekibnhamid642 Před rokem

    Great

  • @lukenukem8028
    @lukenukem8028 Před 4 lety

    Just 1 Q, about returning List:
    It's nice to see someone else do that. But, isn't it important to return a List clone?
    return new List(output); // That was just something I learned early on.
    It was said that, if you return output;, then you're returning a reference to that local List instead of setting your external List to those contents.

    • @IAmTimCorey
      @IAmTimCorey  Před 4 lety +2

      You are returning the list but typically that is what you want. Making a copy of the list duplicates the memory but doesn't usually add value. Unless you find that you want to manipulate the list in the calling class and the called class separately, just use the same list.