Advertisement
Поиск  
Always will be ready notify the world about expectations as easy as possible: job change page
May 16, 2022

Best LINQ performance

Автор:
Hussein NM
Источник:
Просмотров:
1597

In this article, I will show the most performant way to write queries for a collection of objects in .Net Core. The article discusses the common methods of LINQ and their comparison. After reading this article, you may have to review your project code!

Comparisons were made between query syntax, called LINQ, and method syntax called LAMBDA.

💡 Connect with me on LinkedIn: https://www.linkedin.com/in/hussein-nm/

✨ Where()

LINQ_Where (Method name):

LAMBDA_Where:

🚀 Performance

Which one do you think is faster?

In this simple performance query, both methods are similar.

✨ Any()

LINQ_Any:

LAMBDA_Where_Any:

LAMBDA_Any:

🚀 Performance

Using Any() as the LAMBDA_Any method is faster.

✨ First()

LINQ_First:

LAMBDA_Where_First:

LAMBDA_First:

🚀 Performance

Using First() as the method a LAMBDA call is faster.

✨ FirstOrDefault()

LINQ_FirstOrDefault:

LAMBDA_Where_FirstOrDefault:

LAMBDA_FirstOrDefault:

🚀 Performance

Using FirstOrDefault() as the method a LAMBDA call is faster.

✨ Last()

LINQ_Last:

LAMBDA_Where_Last:

LAMBDA_Last:

🚀 Performance

Using Last() as the method a LAMBDA call is faster.

✨ LastOrDefault()

LINQ_LastOrDefault:

LAMBDA_Where_LastOrDefault:

LAMBDA_LastOrDefault:

🚀 Performance

Using LastOrDefault() as the method a LAMBDA call is faster.

Conclusion

As shown in this article, you should always use Any(), First(), FirstOrDefault(), Last(), LastOrDefault, or Where() at the beginning of a LAMBDA statement.

Похожее
Jul 7, 2021
Author: Changhui Xu
C# has a feature, String Interpolation, to format strings in a flexible and readable way. The following example demonstrates the way how we usually output a string when we have data beforehand then pass data to the template string.var name...
Aug 26, 2021
Author: Dumindu De Silva
What is .Net 5.Net 5 is one of the major and latest releases of Microsoft’s .NET family. It comes with many exciting features compared to the previous released .Net core. The primary goal with the release of .Net 5 is...
Feb 1
Author: Sohail Aslam
IntroductionWelcome to the world of C#! Whether you’re a seasoned developer or just starting your programming journey, the power and versatility of C# can elevate your coding experience. In this article, we’ll explore a curated collection of tips and tricks...
Jul 11, 2021
Author: Sasha Mathews
In C#, reference types can be assigned null values. This is something that developers will have to live with until they use classes to create software. Unfortunately, the folks at Microsoft cannot simply disallow null assignment to reference variables at...
Написать сообщение
Почта
Имя
*Сообщение


© 1999–2024 WebDynamics
1980–... Sergey Drozdov
Area of interests: .NET Framework | .NET Core | C# | ASP.NET | Windows Forms | WPF | HTML5 | CSS3 | jQuery | AJAX | Angular | React | MS SQL Server | Transact-SQL | ADO.NET | Entity Framework | IIS | OOP | OOA | OOD | WCF | WPF | MSMQ | MVC | MVP | MVVM | Design Patterns | Enterprise Architecture | Scrum | Kanban