Advertisement
Guest User

Untitled

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