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 TestShit
- {
- class Program
- {
- static void Main(string[] args)
- {
- //Example arsa = Test<Example>.GetInstance(3);
- var a = Singleton<Example>.GetInstance(4);
- var f = Singleton<Example>.GetInstance(47);
- var news = new Example(57);
- }
- class Example
- {
- int a;
- public Example()
- {
- }
- public Example(int a)
- {
- this.a = a;
- }
- }
- class MyClass
- {
- }
- class Singleton<T> where T:new()
- {
- static T instance;
- public static T GetInstance()
- {
- if (instance == null)
- {
- instance = (T)Activator.CreateInstance(typeof(T), null);
- }
- return instance;
- }
- public static T GetInstance(int a)
- {
- if (instance == null)
- {
- instance = (T)Activator.CreateInstance(typeof(T), a);
- }
- return instance;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement