.net, C# and programming

Hunting the N+1 Query Problem with a Roslyn Analyzer Read in English

Most collection-related performance advice stops at the method boundary: avoid redundant ToArray() calls, pre-size your List<T>, swap a linear Contains() scan for a HashSet<T>. Those micro-optimizations matter, but they pale in comparison to a much bigger and much more common mistake — the N+1 Query Problem.

Read more...

AutoMapper: Find Usages Read in English

AutoMapper is a popular .NET library for automating object-to-object mapping. It allows developers to easily map objects between different types, reducing the amount of boilerplate code required for data transfer and transformation. But it's easy to miss data flow using AutoMapper because it's not immediately obvious where the mapping is happening. For example, you want to know where a specific property is set, but the IDE says "Usages were not found".

I thought about this problem and came up with a solution.

Read more...

Collections search Read in English

During interviews, we often hear — or say ourselves — that searching in an array is slower than in a hashtable. Some might even recall that array search has linear complexity, or O(n), while a hash table has constant complexity, O(1). But does this hold true in practice? What if there are situations where searching in an array turns out to be faster? Let's not rush to conclusions.

Read more...

Удаляем пробелы из строки Читать на русском

Еще одна популярная задача при работе со строками — удалить из них пробельные символы. Можно представить, что нам нужно очистить пользовательский ввод (удалить пробелы вначале и конце строк в имени) или минифицировать json-объект. .NET предоставляет нам несколько возможностей для решения этой задачи, давайте рассмотрим самые популярные и попробуем найти наиболее эффективные. Заодно проверим, какие изменения произошли в новой версии .NET 10.

Read more...

Инициализатор коллекций: List<T> Читать на русском

Мы все привыкли писать new List<int> { 1, 2, 3, 4 } или new int[] { 1, 2, 3, 4}, чтобы инициализировать коллекции какими-то значениями. Синтаксически это выглядит похоже, но поведение отличается, и вам следует быть осторожными, если вы заботитесь о производительности.

Read more...