Publicidad
Patrocinador Verificado
Infraestructura Cloud, GPU Clusters y APIs de IA para Desarrolladores
Despliega pipelines de inferencia y trading con latencia ultra baja. Explora planes.
Conocer Más →

Cheatsheet de C# LINQ y Expresiones: Sintaxis de Consulta y Métodos

Domina C# Language Integrated Query (LINQ), ejecución diferida (IEnumerable vs IQueryable), proyecciones Select/SelectMany, agrupaciones GroupBy y uniones de datos de alto rendimiento.

🧪
Ejecuta y Edita este Código en Vivo Sin instalaciones locales. Soporta Python 3, JS y SQL.
Probar en Playground →

1. Essential LINQ Transformations

LINQ operators use deferred execution until materialized by ToList(), ToArray(), or enumeration via foreach.

CODE SNIPPET
// Filtering and transforming collections
var highValueCustomers = customers
    .Where(c => c.IsActive && c.TotalPurchases > 1000)
    .OrderByDescending(c => c.TotalPurchases)
    .Select(c => new { c.Id, c.FullName, Tier = "VIP" })
    .ToList();

// GroupBy aggregation
var salesByCategory = orders
    .GroupBy(o => o.Category)
    .Select(g => new { Category = g.Key, TotalRevenue = g.Sum(x => x.Price) });

2. C# Records and Value Equality

Records provide built-in value-based equality, concise syntax, and safe immutability for domain models and DTOs.

CODE SNIPPET
// Positional record declaration with immutable properties
public record Developer(string Name, string Language, int ExperienceYears);

// Non-destructive mutation using 'with' expression
var dev1 = new Developer("Alex", "C#", 5);
var dev2 = dev1 with { Language = "F#" };

// Value-based equality check (returns true)
bool areEqual = dev1 == new Developer("Alex", "C#", 5);
Publicidad
Patrocinador Verificado
Trading Cuantitativo y 30 Modelos de Negocio con IA
Genera ingresos predecibles con retainers mensuales y bots automatizados.
Ver Blueprints →

3. Memory Optimization with ReadOnlySpan<T>

ReadOnlySpan allows slicing contiguous memory without triggering heap allocations or garbage collection pressure.

CODE SNIPPET
// Zero-allocation string parsing using ReadOnlySpan
string log = "2026-09-12|ERROR|ServiceUnavailable";
ReadOnlySpan<char> span = log.AsSpan();

int firstDelimiter = span.IndexOf('|');
ReadOnlySpan<char> dateSpan = span.Slice(0, firstDelimiter);
ReadOnlySpan<char> rest = span.Slice(firstDelimiter + 1);

int secondDelimiter = rest.IndexOf('|');
ReadOnlySpan<char> levelSpan = rest.Slice(0, secondDelimiter);

🚀 Ruta de Aprendizaje y Modelos de Negocio Asociados

📚 Guía Completa Paso a Paso

Guía Maestra de C# LINQ & Rendimiento en Memoria

Ejecución diferida, proyecciones avanzadas y optimización de memoria con Spans.

Leer Guía Completa →
💰 Modelo de Negocio Monetizable

Modernización de Código Legacy con IA ($2,500/mes)

Migra sistemas empresariales monolíticos a microservicios modernos en .NET 9.

Ver Plan de Negocio →

¿Necesitas otra hoja de trucos?

Añadimos nuevas guías de referencia cada semana según las peticiones de la comunidad.

Solicitar una Cheatsheet →