.NET / C#
Enterprise application development concepts covering CLR, LINQ, and Memory Management.
Interview Questions
26 TotalWhat is the Common Language Runtime (CLR)?
The CLR is the execution engine of the .NET framework that manages running code. It provides memory management (Garbage Collection), thread management, exception handling, and security.
Explain the difference between `IEnumerable` and `IQueryable` in LINQ.
`IEnumerable` executes queries in-memory on the client side, while `IQueryable` translates queries into SQL and executes them on the database server side. `IQueryable` is used to filter data BEFORE it reaches the application.
What is a Garbage Collector (GC) in .NET?
The GC automatically manages the allocation and release of memory for an application. Developers don't have to write code to perform memory management tasks, preventing memory leaks.
What are the main differences between a Class and a Struct in C#?
Classes are Reference Types allocated on the Heap. Structs are Value Types typically allocated on the Stack. Structs do not support inheritance like Classes do.
What is the difference between 'continue' and 'break' statements in C#?
The 'continue' statement skips the rest of the code in the current iteration and moves to the next iteration, while the 'break' statement terminates the loop entirely.
How does the 'using' statement in C# ensure resource cleanup?
The 'using' statement ensures that the Dispose method of an IDisposable object is called, even if an exception occurs, thus ensuring resource cleanup.
What is the purpose of the 'sealed' keyword in C#?
The 'sealed' keyword prevents a class from being inherited, thus restricting its use as a base class.
Can you explain the concept of 'covariance' and 'contravariance' in C#?
Covariance refers to the ability of a generic type to be used as a more specific type, while contravariance refers to the ability of a generic type to be used as a less specific type.
How does the 'async/await' syntax in C# simplify asynchronous programming?
The 'async/await' syntax allows developers to write asynchronous code that is easier to read and maintain, by avoiding the need for explicit callback methods and thread management.
What is the difference between 'typeof' and 'GetType()' in C#?
The 'typeof' operator returns the Type object for a given type, while the 'GetType()' method returns the Type object for the current instance.
Can you explain the concept of ' Boxing' and 'Unboxing' in C#?
Boxing is the process of converting a value type to a reference type, while unboxing is the process of converting a reference type to a value type.
What is the purpose of the 'yield' keyword in C#?
The 'yield' keyword is used to implement iterators, allowing developers to create custom iteration logic for collections and other data structures.
How does the 'Garbage Collector' in .NET manage memory?
The Garbage Collector automatically reclaims memory occupied by objects that are no longer in use, thus preventing memory leaks and optimizing system performance.
Can you explain the difference between 'override' and 'new' keywords in C#?
The 'override' keyword is used to provide a specific implementation for a method that is already defined in its base class, while the 'new' keyword is used to hide a method of the base class.
What is the purpose of the 'IDisposable' interface in C#?
The 'IDisposable' interface provides a standard way for classes to release unmanaged resources, such as file handles or database connections, when they are no longer needed.
How does the 'Parallel.ForEach' method in C# simplify parallel programming?
The 'Parallel.ForEach' method allows developers to execute a loop in parallel, automatically dividing the work among multiple threads and managing thread synchronization.
Can you explain the concept of 'Lazy Loading' in C#?
Lazy loading is a technique that delays the initialization of an object until its value is actually needed, thus improving performance by reducing unnecessary computations.
What is the difference between 'string' and 'String' in C#?
The 'string' keyword is an alias for the 'System.String' class, while 'String' is the actual class name.
How does the 'PLINQ' framework in C# simplify parallel query execution?
PLINQ (Parallel Language Integrated Query) allows developers to execute LINQ queries in parallel, automatically dividing the work among multiple threads and managing thread synchronization.
Can you explain the concept of 'memoization' in C#?
Memoization is an optimization technique that stores the results of expensive function calls so that they can be reused instead of recalculated, thus improving performance.
What is the purpose of the 'async Main' method in C#?
The 'async Main' method allows the main entry point of a console application to be asynchronous, thus enabling the use of async/await syntax in the main method.
How does the 'Span<T>' type in C# improve performance in certain scenarios?
The 'Span<T>' type allows for efficient manipulation of contiguous regions of memory, thus improving performance in scenarios such as parsing and processing large datasets.
Can you explain the concept of 'immutable objects' in C#?
Immutable objects are objects whose state cannot be modified once they are created, thus providing thread safety and improving code maintainability.
What is the difference between 'Task.Run' and 'Task.Factory.StartNew' in C#?
Both 'Task.Run' and 'Task.Factory.StartNew' are used to start a new task, but 'Task.Run' is a simpler and more convenient way to start a task, while 'Task.Factory.StartNew' provides more advanced options for task creation.
How does the 'IQueryable<T>' interface in C# enable database queries to be executed remotely?
The 'IQueryable<T>' interface allows LINQ queries to be executed remotely on a database server, thus enabling efficient data retrieval and reducing the amount of data transferred over the network.
Can you explain the concept of 'Expression Trees' in C#?
Expression trees are data structures that represent code as a tree-like structure, allowing for dynamic creation and manipulation of code at runtime.