What is the below piece of code performing

namespace ConsoleApplication1
{
public sealed class Singleton
{
private static Singleton instance = null;
private static readonly object lockObj = new object();

Singleton(){} //private constructor

public static Singleton Instance
{
get
{
lock (lockObj)
{
if (System.Object.ReferenceEquals(instance, null))
{
instance = Inner.Instance;
}
return instance;
}
}
}

class Inner
{
Inner(){ }//private constructor

public static Singleton Instance
{
get
{
return new Singleton();
}
}
}
}
}

 Posted by Rajnilari2015 on 12/5/2015 | Category: C# Interview questions | Views: 649 | Points: 40
Select from following answers:
  1. Creating a Singleton Class using the concept of Inner Class
  2. An Example of Encapsulation demonstrated using Inner Class.
  3. Compile error
  4. Answer 1 and Answer 2
  5. All Above

Show Correct Answer


Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response