Skip to main content

Stage 5 - Collections, LINQ, and Strings

Q32. What is a collection?

Quick interview answer: A collection stores multiple items in one object. Common examples are List<T> for ordered data, Dictionary<TKey, TValue> for key-based lookup, and HashSet<T> for unique values.

Study in detail: Collections - This article expands the topic with complete explanation, examples, and practice code.

Q33. When should we use Dictionary?

Quick interview answer: Use Dictionary when you want to find a value quickly using a key. For example, we can find a student by admission number instead of searching the whole list.

Study in detail: Collections - This article expands the topic with complete explanation, examples, and practice code.

Q34. What is LINQ?

Quick interview answer: LINQ is a way to query data using C# syntax. It helps us filter, sort, group, and select data from collections, databases, and other sources in a readable way.

var passedStudents = students
.Where(s => s.Marks >= 35)
.ToList();

Study in detail: LINQ - This article expands the topic with complete explanation, examples, and practice code.

Q35. What is deferred execution in LINQ?

Quick interview answer: Deferred execution means a LINQ query does not run immediately when it is created. It runs only when we read the result, such as with foreach, ToList(), Count(), or FirstOrDefault().

Study in detail: LINQ and Iterators - This article expands the topic with complete explanation, examples, and practice code.

Q36. Why are strings immutable?

Quick interview answer: Strings are immutable, which means once a string is created it cannot be changed. When we modify a string, C# creates a new string. For many repeated changes, StringBuilder is more efficient.

Study in detail: Strings - This article expands the topic with complete explanation, examples, and practice code.

nexcoding.in