Reference Page: C-Language|C++|C#|VB.Net|Asp.Net

C++ Links : Learn     Interview Questions     Software IDE C++ Jobs : Indeed.com     ZipRecruiter.com     Monster.com

C# Interview Questions - Page 8

< Previous Page
Question: What is method hiding in C#?
Answer: The method hiding in C# occurs when a derived class defines a method with the same name and signature as a method in its base class, effectively hiding the base class method.

This can lead to confusion and unexpected behavior, so it is generally recommended to use method overriding (with the 'override' keyword) instead of method hiding when extending classes.

Question: How do you handle exceptions in parallel processing with Tasks in C#?
Answer: Exceptions thrown by tasks can be handled using try-catch blocks within the task's code or by using the Task.Exception property to access the exception thrown by a task after it completes.

Additionally, the AggregateException class can be used to aggregate multiple exceptions thrown by parallel tasks.

Question: What is the purpose of the Parallel class in C#?
Answer: The Parallel class in C# provides static methods for parallelizing loops, executing parallel tasks, and performing parallel LINQ queries.

It simplifies writing parallel code by abstracting away low-level details and providing high-level constructs for parallel execution.

Question: What is PLINQ in C#?
Answer: The PLINQ (Parallel LINQ) is an extension of LINQ (Language Integrated Query) provided by the Task Parallel Library (TPL) in C#.

It enables parallel execution of LINQ queries by automatically partitioning the data source and processing the partitions concurrently on multiple CPU cores, leading to improved query performance for large data sets.

Question: How do you control parallelism in the Task Parallel Library (TPL) in C#?
Answer: Parallelism in the Task Parallel Library can be controlled using options such as ParallelOptions.MaxDegreeOfParallelism, which specifies the maximum number of concurrent tasks to execute.

Additionally, parallel loops and parallel LINQ queries provide options for specifying parallelism settings to control the degree of parallelism.
Question: What is the purpose of the Interlocked class in C# parallel programming?
Answer: The Interlocked class in C# provides atomic operations for common synchronization primitives, such as incrementing and decrementing integers, exchanging values, and performing bitwise operations.

It ensures that these operations are performed atomically and thread-safe without the need for explicit locks or synchronization mechanisms.

Question: What is a concurrent collection in C#?
Answer: A concurrent collection in C# is a type of collection that is designed to be safely accessed and modified by multiple threads concurrently without the need for external synchronization.

Examples of concurrent collections include ConcurrentQueue, ConcurrentStack, ConcurrentBag, and ConcurrentDictionary.


< Previous Page