Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace revision
- {
- internal class TestSingleton
- {
- // Make the constructor private
- private TestSingleton() {
- // Only First time you call the instnce object it execute the constructor
- Thread.Sleep(3000);
- }
- public static object _lock = new();
- // private instance of the class
- private static TestSingleton _instance;
- // public method to intialize that instance
- public static TestSingleton Instance {
- get {
- lock (_lock) // /to avoid multi threads to create the instance at the same time
- {
- if (_instance == null)
- {
- _instance = new TestSingleton();
- }
- }
- return _instance;
- }
- }
- public int Add(int x, int y)
- { return x + y; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement