Check out my courses: https://nickchapsas.com
Become a Patreon and get source code access: https://www.patreon.com/nickchapsas
Hello everybody I’m Nick and in this video I will show you a couple of new LINQ methods introduced in .NET 7 that you probably shouldn’t be using. There are some even faster and more memory efficient alternatives that you can use instead, depending on your usecase.
Don’t forget to comment, like and subscribe 🙂
Social Media:
Follow me on GitHub: http://bit.ly/ChapsasGitHub
Follow me on Twitter: http://bit.ly/ChapsasTwitter
Connect on LinkedIn: http://bit.ly/ChapsasLinkedIn
Keep coding merch: https://keepcoding.shop
#csharp #dotnet
Thanks to your videos I know how to benchmark my code now. 😁
This is the best free software Ive seen. Respect.
Way to go Nick, thanks for the useful video!
Premature optimization the bane of every unproductive developer.
Shouldn't you re-seed the Random for each Enumerable for the same values, especially with int.ToString()?
6:20 "both of this classes"
Great video Nick! I was really hoping that you would run the benchmarks with the Params attribute to see what happens with 1_000, 10_000 and 1_000_000 sized collections. I would also really like to see the results from the sort using spans method. Really great video though as always! Keep them coming…
I believe that a static lambda like x => x with no closure will not allocate anything. It's compiled as a static method in the using class scope. It can be seen by decompiling the output managed DLL. Only delegates and lambdas that actually capture some state will be compiled to a separate class that then needs to be instantiated (which causes the allocation). No closure delegates will have their object set to null.
Do linq methods perform sort immediately, or can it be deferred or halted. Like say we order and take 100 out of a million, will the performance be the same as we array sort said million. I would benchmark it later, now I am from phone. But if someone beats me to it, you are welcome.
It seems like it would be a simple optimisation to have order call the underlying sort functions. I guess the extension method is on the interface, but it seems like it would be worth it to check the type of the collection.
This comment is unrelated to this video. Hey Nick, I really hate ENUMs. Specifically when newer devs use them in service contracts and change somewhat regularly. Would you mind putting together a video on a more elegant way to handle this topic that doesn't break contacts? I see this specifically in an EntityType or EventType and the moment a new one is added everything breaks.
My brain hurts
Maybe worth pointing out by having three different arrays of different random numbers it can make for inconsistent results
This might sound like a stupid question, but can any body tell me what IDE Nick is using? I'm currently using Visual Studio 2019. I like using it but Nick's seems more responsive than mine.
but I guess I just have to deal with bluetooth, tNice tutorials is a big con.
Theos! You are my defacto no.1 resource for C# on YouTube. Enjoying the flow and straight to the point vids. I tip my hat for you sir 🙂
.NET 7 is available and people are discovering that the methods available from .NET 1.1 can perform better 😀
Order/OrderBy advantages:
+ purity (i.e. doesn't change underlying collection)
+ simplicity
+ readability
+ same for primitive/complex types
+ extension method of IEnumerable<T> => you don't have to have a collection before and ToArray/ToList can be way down the chain of other methods
+ expression tree (allows for other optimizations etc.)
Sort advantages:
+ faster (not always)
+ more memory efficient
So it depends. I believe Order/OrderBy is better choice in most of the cases. Title of the video is a bit misleading.
nice shirt in the thumbnail
to be clear – when you compare sorting methods you should compare this same data sets for each algorithm so instead of creating new collections of random items each time you should create this collection once and work on a copy of this collection
Of course this would not apply to Linq to entities.
What aout sorting objects using a property inside them, I think that's the most important use case.
Can we use List.Sort with IComparison In that case?
How are you on RC1? Site still says SDK 7.0.100-preview.7
This video feels like 12 minutes just to get talked down to and find out something I already knew and would have no problem finding on google if I didn’t…
tldr?
If you like ghelbrubghluru content, and you wanna see more, make sure you subscribe and ring the scrubhshdsdfshsddhaf notification bell ……..