In Focus
Jabalpur Chapter Meet July 13: Register Now
Chandigarh Chapter: Developers Day on 29 June 2013
Delhi Chapter Hands On June 22: Limited Seats Register Now
Email :
Password :
Remember me?
Forgot password
Contribute
An Article
A Blog
A News
A Video
A Link
An Interview Question
Ask a Question
TECHNOLOGIES
.NET 4.5
Chapters
JavaScript, CSS
SharePoint 2010
Web Development
.NET Assemblies
Coding Best Practices
JQuery
SharePoint 2013
Web Services in C#
ADO.NET in C#
Current Affairs
JSP
Silverlight with C#
Windows 8
AJAX in C#
Databases & DBA
Leadership
Smart Devices
Windows Azure
Android Programming
Design & Architecture
Learn .NET
SQL
Windows Controls C#
Articles C#
Exception Handling C#
LightSwitch 2012
SQL Server 2012
Windows Forms C#
ASP.NET Controls in C#
Expression Studio
LINQ
Testing
Windows Phone 8
ASP.NET MVC with C#
Graphics Design
Mobile & Embedded
TypeScript
Windows Server 2012
ASP.NET Programming
How do I
Office 2013
Visual C#
Windows Store Apps
BizTalk Server
HTML 5
OOP/OOD
Visual Studio .NET
Workflow Foundation in C#
C# Language
Internet & Web
Operating Systems
Visual Studio 2010
WPF
C# Tutorials
iPhone/iPad
PHP
Visual Studio 2012
XAML
C, C++, MFC
Java
Products
WCF with C#
XML
Career Advice
Java and .NET
Project Management
Request a new Category
|
View All
ANSWERS
BLOGS
VIDEOS
INTERVIEWS
BOOKS
LINKS
NEWS
CHAPTERS
CAREER ADVICE
iOS 7 beta: Testers warned when using uncert ...
Design Simple Logo with help of Expression D ...
Menu Style like jQuery
Why Constructor can't be declared Virtually? ...
Send Email in HTML Format using SQL database ...
Waiting Message in Window Application using C#
Merging Several Rows into a Single Row in SQ ...
Credit Card Payment in ASP.Net using Stripe.com
How to Move a Folder to Another Folder with ...
Get Values from Client Side to Server Side u ...
Blog
74
1,529
Creating Lazy
- Singleton Class
Posted by
Mahadesh Mahalingappa
in
Blogs
|
C# Language
on
Sep 27, 2011
In this blog we will see how to create a Singleton Class using the Lazy<T> in C#.
Tweet
1586
0
0
Lazy<T> provides support for
Lazy Initialization
.
By Lazy Intialisation we mean that an object is not intialised until it is actually used. Below, I have shown how we can combine the Lazy<T> with the Singleton Pattern.
public sealed class LazySingleton
{
// Private object with lazy instantiation
private static readonly Lazy<LazySingleton> instance =
new Lazy<LazySingleton>(
delegate
{
return new LazySingleton();
}
//thread safety first
, System.Threading.LazyThreadSafetyMode.ExecutionAndPublication);
private LazySingleton()
{
// no public default constructor
}
// static instance property
public static LazySingleton Instance
{
get { return instance.Value; }
}
}
Related Resources
Here is a list of some other related resources:
System.Lazy(Of T) Class
Lazy Initailization in .NET 4.0
Support for
Lazy Initialization
in .Net 4.0
This Feature is Sponsored By
DynamicPDF Merger is a developers dream for interacting with any existing PDF documents. Merge, append, split, form fill, flatten stamp and so much more.
Understanding Reference and poin..
Leverage “using” in C#
comments
View Previous Comments
of
COMMENT USING
PREMIUM SPONSORS
DynamicPDF Developer Components
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
More Blogs from this Blogger
Creating ViewModel in Silverlight
Creating a Multi Value Converters in Silverlight
Silverlight - Drawing a line Programatically
Enable Full Screen in Silverlight
Creating the Item Source for the Observable Collection in Silverlight
Creating a Observable Collection in Silverlight
Creating Glass Effects in Silverlight
Generic Join Method Using LINQ
Fetch by Primary Key using LINQ - Generic
Constructing Lambda in VB.Net
View All
SPONSORED BY
Download Your Free HTML5/jQuery Grid Now!
Make Your Data Do More with the Ignite UI Grid. Launch eye-popping, performance-driven HTML5 apps w/ Ignite UI's free jQuery Grid.
Follow @twitterapi
Latest Blogs
Why Developers Should Read News
In Defence of Books
Media Player, Real Player, QuickTime Player in ASP.Net
Credit Card Payment in ASP.Net using Stripe.com
Crop Image in ASP.Net using Script
Creating Social Site Buttons By addthis.com in ASP.Net
Internals of C# Events
Design Simple Logo with help of Expression Design
How to get list of all folders in a Dropdown List
Search in Coma delimited string
View All
Poll
Result
All Polls
Speed of C# Corner
How do you find speed of C# Corner when visiting the site?
Very Fast
OK
Slow
Very Slow
How do you find speed of C# Corner when visiting the site?
Options
Votes
%
Very Fast
4
7.69
OK
42
80.77
Slow
4
7.69
Very Slow
2
3.85
Total
52
100%