title: Generic Singleton<T>
body: <p>I have a question, is this the correct approach to make a Generic Singleton?</p>
  
  <pre><code> public class Singleton&lt;T&gt; where T : class, new()
      {
          private static T instance = null;
  
          private Singleton() { }
  
          public static T Instancia
          {
              get 
              {
                  if (instance == null)
                      instance = new T();
                  return instance;
              }
          }
      }
  </code></pre>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Checking some PDFs I found a generic Singleton made this other way, is this other correct? </p>
  
  <pre><code>public class Singleton&lt;T&gt; where T : class, new()
  {
      Singleton() { }
  
      class SingletonCreator
      {
          static SingletonCreator() { }
          // Private object instantiated with private constructor
          internal static readonly T instance = new T();
      }
  
      public static T UniqueInstance
      {
          get { return SingletonCreator.instance; }
      }
  }
  </code></pre>