Feng Yuan’s Post

Please do not talk about method names only. You need at least add class name, may be the whole namespace. Here All is LINQ.Enumerable method, TrueForAll is available on a few classes like List<T>, Array, and classes in Immutable namespace. Semantically, they are the same. Another proof that LINQ Is Not Quick.

View profile for SERKUT YILDIRIM, graphic

Microsoft MVP | Helpful Posts About .NET, C# and Visual Studio

💡 𝐂#/.𝐍𝐄𝐓 𝐏𝐞𝐫𝐟𝐨𝐫𝐦𝐚𝐧𝐜𝐞 𝐓𝐢𝐩 🔥   💎𝐀𝐥𝐥() 𝐯𝐬 𝐓𝐫𝐮𝐞𝐅𝐨𝐫𝐀𝐥𝐥() 𝐁𝐞𝐧𝐜𝐡𝐦𝐚𝐫𝐤 𝐓𝐞𝐬𝐭 𝐢𝐧 .𝐍𝐄𝐓 𝟖.𝟎 💡 You should prefer to use 𝐓𝐫𝐮𝐞𝐅𝐨𝐫𝐀𝐥𝐥() instead of 𝐀𝐥𝐥() method with collections. ⚡ The 𝐀𝐥𝐥() method checks for all the elements in a collection and returns a boolean. It is used with lambda expressions or predicates. Even if one of the element do not satisfy the set condition, the All() method returns False, otherwise True. ⚡ The 𝐓𝐫𝐮𝐞𝐅𝐨𝐫𝐀𝐥𝐥() method takes a predicate delegate as an argument and checks whether all elements in the collection satisfy the specified conditions and returns a boolean. Even if one of the element do not satisfy the set condition, the TrueForAll() method returns False, otherwise True. ✅ 𝐀𝐥𝐥() 𝐢𝐬 𝐦𝐨𝐫𝐞 𝐠𝐞𝐧𝐞𝐫𝐚𝐥 𝐭𝐡𝐚𝐧 𝐭𝐡𝐞 𝗧𝗿𝘂𝗲𝗙𝗼𝗿𝗔𝗹𝗹() method. 🔥 𝗧𝗿𝘂𝗲𝗙𝗼𝗿𝗔𝗹𝗹() method can be more efficient than All(), especially for large collections such as 𝐋𝐢𝐬𝐭, 𝐀𝐫𝐫𝐚𝐲, 𝐈𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞𝐋𝐢𝐬𝐭 𝐚𝐧𝐝 𝐦𝐦𝐮𝐭𝐚𝐛𝐥𝐞𝐋𝐢𝐬𝐭.𝐁𝐮𝐢𝐥𝐝𝐞𝐫 collection types. This is because TrueForAll() can use the underlying implementation of the collection to iterate over the elements in the most efficient way possible. #csharp #dotnet #programming #softwareengineering #softwaredevelopment

  • No alternative text description for this image
Md. Alim Ul Karim

Hiring 🚀Chief Software Architect ✅ Staff Augmentation | C# | Golang | Microservices | Redis | ASP.NET | MVC | .NET Core | .NET | Aws | Azure | NodeJS | JS | React JS | Kubernetes | k8s | Redux | EF | SQL | AI

6mo

In most cases I don't trust his benchmark. Good catch Feng Yuan

Paulo Zëmek

Software Engineer - I used talk to computers and they understood me even without AI, we just spoke the same language... now that they got smarter we are so in-sync that sometimes it feels we talk to each-other mentally!

6mo

Interesting that if the List method was also named All it would be used instead of the LINQ method by default. I guess they just wanted a better naming for the LINQ one (or in fact just use a different rule, as All gives me the impression that all the records that match are returned, like a Where, TrueForAll gives me the right impression).

Like
Reply
See more comments

To view or add a comment, sign in

Explore topics