Monday, May 7, 2012

C Sharp Interview Questions with Answers

Here I am going to include some important questions asked in recent interview.This is beneficial for both freshers and experienced.By answering these questions You will leave a good impression on interviewer.
So,now no more talks..start reading and digesting.

What is Mutex?

Mutex is the short form for MUTual EXclusion.
Mutual exclusion refers to the problem of ensuring that no two processes or threads can be in their critical section at the same time. Here, a critical section refers to a period of time when the process accesses a shared resource, such as Shared Memory. The problem of mutual exclusion was first identified and solved by Edsger W. Dijkstra in his seminal 1965 paper titled: Solution of a problem in concurrent programming control.
In C# there is Mutex class defined within System.Threading Namespace

What do You mean by LOCK and Wait?

A Lock is a synchronization mechanism for enforcing limits on access to a resource in an environment where there are many threads of execution. Locks are one way of enforcing concurrency control policies.

A process (or task) may wait on another process to complete its execution. In most systems, a parent process can create an independently executing child process. The parent process may then issue a wait system call, which suspends the execution of the parent process while the child executes. When the child process terminates, it returns an exit status to the operating system, which is then returned to the waiting parent process. The parent process then resumes execution.

Define Static members of the class in the terms of C# -:
Static members belong to whole class rather than to individual object. For example, if you have a static phoneNumber field in your Student class, then there will be the single instance of this field and all the objects of this class will share this single field. Changes made by one object to phone Number will be realized by the other object.
Class Student
    Public static int phoneNumber;
    Public int rollNumber;
Class Test
    Public  static void Main()
        Student  st1=new Student();
        Student st2=new Student();
Here you can see that the phoneNumber is accessed without any reference to the object but with the name of the class it belongs. Static methods are very useful while programming. In fact, the WriteLine() and ReadLine() methods are static methods of Console Class. Even Main () is declared as static as CLR calls it without making any instance of class. It’s useful when we want to cache data that should be available to all objects of class.
Some precautions:
Don’t put too many static methods in your class as it is against the OO design principles and makes your class less extensible.
You tend to loose a number of OO advantages while using static methods, as static methods can’t be overridden which means it cannot be used polymorphically, something widely used in the OO paradigm of programming.

What DoYou mean by Singleton Approach?
This structural code demonstrates the Singleton pattern which assures only a single instance (the singleton) of the class can be created.

No comments:

Post a Comment