Created
July 11, 2020 05:35
-
-
Save AbhinavPradeep/e7a017630c8866c10769a76cb5d2938b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public sealed class SomeExpensiveResource | |
{ | |
private static readonly Lazy<SomeExpensiveResource> lazy = | |
new Lazy<SomeExpensiveResource>(() => new SomeExpensiveResource()); | |
public static SomeExpensiveResource Instance { get { return lazy.Value; } } | |
private SomeExpensiveResource() | |
{ | |
System.Console.WriteLine($"An expensive resource has been created {this.GetHashCode()}"); | |
} | |
public void UseExpensiveResource() | |
{ | |
System.Console.WriteLine($"The expensive resource is being used - {this.GetHashCode()}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment