Skip to main content

Posts

Showing posts from May, 2024

C# : Interview questions (51-55)

    Questions : What is th e purpose of the "using" directive in C#? How do you d efine a constant in C#? What is the purpose of t he "readonly" keyword in C#? Explain the use of the "v olatile" keyword in C#. What is a property in C #? C# : Interview questions (46-50) Answers : 1. Purpose of the "using" Directive in C#: The "using" directive in C# serves two main purposes: Namespace Importing: It allows you to import namespaces into your code file, enabling you to use types (classes, interfaces, enums, etc.) defined within those namespaces without fully qualifying their names. using System; // Importing the System namespace class Program { static void Main () { Console.WriteLine( "Hello, World!" ); // Using Console class without fully qualifying its name } } Resource Management: When used with disposable types (types that implement the IDisposable interface), the "using" directive e...

C# : Interview questions (46-50)

    Questions : Explain the pu rpose of the lock statement in C#. What is a sem aphore? How do you handle asynchronous programming in C#? What is the "async" and "await" key words used for? Explain the difference between "Task " and "Thread" in C#. C# : Interview questions (41-45) Answers : Purpose of the lock Statement in C#: The lock statement in C# is used to synchronize access to shared resources in a multithreaded environment. It ensures that only one thread at a time can execute a critical section of code by acquiring an exclusive lock on a specified object, known as a synchronization object or lock object. object lockObject = new object (); lock (lockObject) { // Critical section: Access shared resources } In this example, the lock statement ensures that only one thread can enter the critical section of code at a time by acquiring a lock on the lockObject . Other threads attempting to enter the same critical section will be blo...

C# : Interview questions (41-45)

  Questions : What is the purpo se of the Thread class? Explain the difference between a threa d and a process. How do you synchronize threads in C#? What is deadlock in multithre ading? What is a mu tex? C# : Interview questions (36-40) Answers : Purpose of the Thread Class: The Thread class in C# is used to create and control threads, which are independent sequences of execution within a process. Threads allow multiple tasks to execute concurrently, enabling parallelism and multitasking in applications. The Thread class provides methods to start, pause, resume, and terminate threads, as well as facilities for thread synchronization and coordination. Difference between a Thread and a Process: Thread: A thread is the smallest unit of execution within a process. Threads within the same process share the same memory space and resources, including code, data, and file handles. Threads are lightweight compared to processes and have less overhead when switching between them. Threads ca...