๐๐ก๐๐ญ ๐ข๐ฌ ๐๐จ๐ฎ๐ง๐ญ ๐ข๐ง ๐๐ข๐ฌ๐ญ<๐>?
Count is a property of many collections in .Net and its value represents the number of elements in the collection. Its time complexity is O(1).
๐๐ก๐๐ญ ๐ข๐ฌ ๐๐จ๐ฎ๐ง๐ญ() ๐ข๐ง ๐๐ข๐ฌ๐ญ<๐>?
Count() is LINQ extension method for counting elements of a List.
At first, LINQ checks the type, if it is type of collection, it uses the count property. Otherwise, it iterates through all elements to count them. Its time complexity is O(n).
๐ฏ๐๐จ ๐ฐ๐ ๐ซ๐๐๐ฅ๐ฅ๐ฒ ๐๐๐ซ๐ ๐ญ๐ก๐ ๐๐ข๐๐๐๐ซ๐๐ง๐๐?
Yes! For large datasets, itโs better to use the Count property instead of the Count() method whenever possible, because Count() still has the overhead of checking the type and calling the property.
โ ๐๐๐ฏ๐ ๐ฒ๐จ๐ฎ ๐๐ฏ๐๐ซ ๐๐๐๐๐ ๐ฐ๐ข๐ญ๐ก ๐ฌ๐ฎ๐๐ก ๐ฉ๐๐ซ๐๐จ๐ซ๐ฆ๐๐ง๐๐ ๐ข๐ฌ๐ฌ๐ฎ๐? ๐๐ก๐๐ซ๐ ๐ฒ๐จ๐ฎ๐ซ ๐๐ฑ๐ฉ๐๐ซ๐ข๐๐ง๐๐.

Top comments (0)