Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Front Back
- What does LINQ stand for? Language Integrated Query.
- What are the two syntax styles in LINQ? Query syntax (`from x in collection select x;`) and method syntax (`collection.Select(x => x)`).
- What is the difference between `Where()` and `Select()` in LINQ? `Where()` filters elements, while `Select()` transforms them.
- What does `FirstOrDefault()` do in LINQ? Returns the first matching element or `default` if no match is found.
- What is the difference between `First()` and `FirstOrDefault()`? `First()` throws an exception if no elements match, while `FirstOrDefault()` returns `default`.
- What does `SingleOrDefault()` do in LINQ? Returns the only matching element or `default` if no match is found; throws if multiple matches exist.
- What is the difference between `Single()` and `SingleOrDefault()`? `Single()` throws an exception if there is more than one match, while `SingleOrDefault()` allows zero results.
- How do you order elements in LINQ? Using `OrderBy()` and `OrderByDescending()`.
- How do you sort by multiple criteria in LINQ? Using `ThenBy()` and `ThenByDescending()`.
- How do you group elements in LINQ? Using `GroupBy()`: `var grouped = people.GroupBy(p => p.Age);`
- What is `SelectMany()` used for? Flattens nested collections into a single collection.
- What is the difference between `Select()` and `SelectMany()`? `Select()` returns a collection of collections, while `SelectMany()` flattens the result.
- What is the difference between `ToList()` and `ToArray()`? `ToList()` returns a `List<T>`, while `ToArray()` returns an array.
- What does `Distinct()` do in LINQ? Removes duplicate elements from a collection.
- What does `Skip()` do in LINQ? Skips a specified number of elements from the beginning of the collection.
- What does `Take()` do in LINQ? Takes a specified number of elements from the beginning of the collection.
- How do you retrieve the last N elements of a collection using LINQ? Using `.Skip(collection.Count - N)`.
- What does `Any()` do in LINQ? Returns `true` if any elements match a condition.
- What does `All()` do in LINQ? Returns `true` if all elements match a condition.
- What is the difference between `Any()` and `All()`? `Any()` checks if at least one element matches, `All()` checks if every element matches.
- What does `Aggregate()` do in LINQ? Performs a cumulative operation on elements, like summing or concatenation.
- What does `Sum()` do in LINQ? Calculates the sum of numeric values in a collection.
- What does `Average()` do in LINQ? Calculates the average of numeric values in a collection.
- What does `Min()` do in LINQ? Finds the smallest value in a collection.
- What does `Max()` do in LINQ? Finds the largest value in a collection.
- What is the difference between `Count()` and `LongCount()`? `Count()` returns an `int`, while `LongCount()` returns a `long` for large datasets.
- What is the difference between `Join()` and `GroupJoin()` in LINQ? `Join()` performs an inner join, while `GroupJoin()` groups the results.
- How do you perform a left join in LINQ? Using `GroupJoin()` with `DefaultIfEmpty()`.
- What does `Except()` do in LINQ? Returns elements that exist in one collection but not another.
- What does `Intersect()` do in LINQ? Returns elements that exist in both collections.
- What does `Union()` do in LINQ? Combines two collections and removes duplicates.
- What is the difference between `Union()` and `Concat()`? `Union()` removes duplicates, while `Concat()` simply merges collections without filtering duplicates.
- How do you check if two collections contain the same elements? Using `SequenceEqual()`.
- What does `DefaultIfEmpty()` do in LINQ? Returns a default value if a collection is empty.
- What is the purpose of `ElementAt()` in LINQ? Retrieves an element at a specific index.
- How do you reverse a collection in LINQ? Using `Reverse()`.
- What is Parallel LINQ (PLINQ)? A feature that enables parallel execution of LINQ queries for performance optimization.
- How do you enable PLINQ? By using `.AsParallel()`: `collection.AsParallel().Where(x => x > 10).ToList();`
- What is `AsEnumerable()` used for in LINQ? It converts a queryable collection to an `IEnumerable<T>` to execute further operations in memory.
- How do you improve LINQ query performance? Using `AsNoTracking()`, caching results, and limiting in-memory operations.
- What is deferred execution in LINQ? Query execution is delayed until the results are actually iterated.
- What is immediate execution in LINQ? When methods like `ToList()`, `ToArray()`, or `Count()` force execution immediately.
- What are expression trees in LINQ? A way to represent code as data, used in `IQueryable<T>` queries.
- What is the difference between `IEnumerable<T>` and `IQueryable<T>`? `IEnumerable<T>` executes queries in memory, while `IQueryable<T>` allows translation into database queries.
- How does `Chunk()` work in C# 12 LINQ? It splits a collection into fixed-size chunks: `var chunks = collection.Chunk(3);`
- How do you efficiently remove duplicates from a large dataset? Using `Distinct()` or a `HashSet<T>`.
- How do you efficiently paginate data using LINQ? Using `Skip((page - 1) * pageSize).Take(pageSize)`.
- What does `Range()` do in LINQ? Generates a sequence of numbers: `Enumerable.Range(1, 10);`
- What does `Repeat()` do in LINQ? Creates a sequence with repeated values: `Enumerable.Repeat("Hello", 5);`
- What does `Empty<T>()` do in LINQ? Returns an empty sequence of type `T`.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement