Saturday 18 June 2011

C# - Singleton Class using Lazy <T> in Dotnet .40

Code Snippet,

public sealed class Singleton
{
private static readonly Lazy lazy =
new Lazy(() => new Singleton());

public static Singleton Instance { get { return lazy.Value; } }

private Singleton()
{
}
}

Reference:-http://csharpindepth.com/Articles/General/Singleton.aspx

4 comments:

  1. Excellent pieces. Keep posting such kind of information on your blog. I really impressed by your blog.
    Vee Eee Technologies| Vee Eee Technologies|

    ReplyDelete
  2. Replies
    1. Yes,as long as declaration is with 'static' .

      Delete
  3. At our best salon in Noida Sector 76
    , we are dedicated to providing top-notch salon services that cater to your beauty and grooming needs. Our experienced team of professional hairstylists, estheticians, and makeup artists are ready to offer you a range of exceptional services in a warm and welcoming environment.

    ReplyDelete