c# singleton
C#
using System;
namespace DesignPattern.Singleton
{
class Program
{
var printer1 = Printer.GetInstance();
var printer2 = Printer.GetInstance();
Console.WriteLine(printer1.GetHashCode()); //output 20538874
Console.WriteLine(printer2.GetHashCode()); //output 20538874
//both printer1 and printer2 has the same hash code
//that is the same instance
}
public class Printer
{
private static Printer instance;
private Printer(){}
public static Printer GetInstance()
{
if (instance == null)
{
instance = new Printer();
}
return instance;
}
}
}public class SingletonOnDemand {
private SingletonOnDemand () {}
private static class Singleton {
private static final SingletonOnDemand instance = new SingletonOnDemand();
}
public static SingletonOnDemand getInstance () {
System.out.println("create instance");
return Singleton.instance;
}
}
Also in C#:
- Title
- c# arraylist
- Category
- C#
- Title
- get random number c#
- Category
- C#
- Title
- how to disable a gameObject unity c#
- Category
- C#
- Title
- unity create a child object
- Category
- C#
- Title
- unity cycle children
- Category
- C#
- Title
- c# foreach namevaluecollection
- Category
- C#
- Title
- how to stop window from terminating c# visual studio
- Category
- C#
- Title
- c# get list of all class fields
- Category
- C#
- Title
- c sharp substring
- Category
- C#
- Title
- unity get all by tag
- Category
- C#
- Title
- polling data source c# using threads
- Category
- C#
- Title
- unity c# write line
- Category
- C#
- Title
- c# inline if
- Category
- C#
- Title
- move towards target unity
- Category
- C#
- Title
- c# class to byte array
- Category
- C#
- Title
- c# get binary array from int
- Category
- C#
- Title
- c# filter non alphanumeric characters
- Category
- C#
- Title
- can't add an editor script
- Category
- C#
- Title
- asp.net render control to string
- Category
- C#
- Title
- whats a string
- Category
- C#
- Title
- iteration c#
- Category
- C#
- Title
- c# console delay
- Category
- C#
- Title
- c# download string url
- Category
- C#
- Title
- Assets/Scripts/Snake.cs(187,10): error CS0029: Cannot implicitly convert type `UnityEngine.Vector2Int' to `System.Collections.Generic.List<UnityEngine.Vector2Int>'
- Category
- C#
- Title
- c# read char
- Category
- C#
- Title
- unity hide mouse
- Category
- C#
- Title
- c# checksum
- Category
- C#
- Title
- what does gameobject.find return
- Category
- C#
- Title
- index in foreach c#
- Category
- C#
- Title
- unity 2d joystick controls
- Category
- C#
- Title
- wpf binding ancestor codebehind
- Category
- C#
- Title
- return random from enum
- Category
- C#
- Title
- unity round
- Category
- C#
- Title
- get hash c#
- Category
- C#
- Title
- round vector3 unity
- Category
- C#
- Title
- mouseposition unity
- Category
- C#
- Title
- how to parse a string to an integer c#
- Category
- C#
- Title
- what data type should be for contact number in asp.net
- Category
- C#
- Title
- c# creating and throwing exceptions
- Category
- C#
- Title
- generics in c#
- Category
- C#
- Title
- value is null to insert in c#
- Category
- C#
- Title
- C# how to expose an internal class to another project in the solution
- Category
- C#
- Title
- unity getkey keycode
- Category
- C#
- Title
- c# mongodb update multiple fields
- Category
- C#
- Title
- c# else if
- Category
- C#
- Title
- unity random float
- Category
- C#
- Title
- invalidoperationexception c# ui thread
- Category
- C#
- Title
- C# get pc language
- Category
- C#
- Title
- wpf datatrigger enum binding
- Category
- C#
- Title
- unity hide mouse first person
- Category
- C#
- Title
- when do i need to end a sentence with ; in c#
- Category
- C#
- Title
- isInstanceOf nunit
- Category
- C#
- Title
- increase variable C#
- Category
- C#
- Title
- c# array Reverse method
- Category
- C#
- Title
- c# list length
- Category
- C#
- Title
- c# loop
- Category
- C#
- Title
- csharp create array list
- Category
- C#
- Title
- c# empty array
- Category
- C#
- Title
- comment envoyer un socket C#
- Category
- C#
- Title
- regex in c#
- Category
- C#
- Title
- c# creating a data recovery software
- Category
- C#
- Title
- copy to clipboard unbity
- Category
- C#
- Title
- math class C# exponents
- Category
- C#
- Title
- unity get max occurrence in list
- Category
- C#
- Title
- c# how to delete a file
- Category
- C#
- Title
- unity ai wander script
- Category
- C#
- Title
- iphone
- Category
- C#
- Title
- c# add object to array
- Category
- C#
- Title
- html hidden text
- Category
- C#
- Title
- c# creating exceptions
- Category
- C#
- Title
- BCrypt c#
- Category
- C#
- Title
- message authorization has been denied for this request. fiddler
- Category
- C#
- Title
- git checkout reset hard
- Category
- C#
- Title
- mysql C# select pk and all columns datareader
- Category
- C#
- Title
- instantiate offset unity
- Category
- C#
- Title
- Movement 2d unity
- Category
- C#
- Title
- how to add a componet to a gameobject throgh code unity
- Category
- C#
- Title
- unity how to change rotation
- Category
- C#
- Title
- how to display an image url in c# picturebox
- Category
- C#
- Title
- c# string to float
- Category
- C#
- Title
- string format c#
- Category
- C#
- Title
- how to start grid from where the data starts in c# charts
- Category
- C#
- Title
- unity get number of child objects
- Category
- C#
- Title
- Basic fps camera C#
- Category
- C#
- Title
- c# enum default
- Category
- C#
- Title
- how to cjeck if a string has a word c#
- Category
- C#
- Title
- c# asp.net hover tooltip
- Category
- C#
- Title
- datagridview column color c#
- Category
- C#
- Title
- unity ui change sprite
- Category
- C#
- Title
- How to look at an object unity
- Category
- C#
- Title
- c# get time
- Category
- C#
- Title
- c# sort array
- Category
- C#
- Title
- freeze rotation in code c#
- Category
- C#
- Title
- : ? conditioanl statement c#
- Category
- C#
- Title
- c# float to string
- Category
- C#
- Title
- out parameters c#
- Category
- C#
- Title
- C# Into To Tring Debug.Log
- Category
- C#
- Title
- c# odd even median
- Category
- C#
- Title
- change Backcolor c#
- Category
- C#
- Title
- c# print
- Category
- C#