Wednesday 8 July 2015

Generic class with optional parameter

public class Generic<T>
      where T : new()
    {
        private T objClass;
        public T ClassInstance
        {
            get
            {
                if (objClass == null)
                {
                    objClass = new T();
                }
 
                return objClass;
            }
        }
    }
 
    public class Generic<T, T1> : Generic<T>
        where T1 : new()
        where T : new()
    {
        private T1 objClass1;
        public T1 ClassInstance1
        {
            get
            {
                if (objClass1 == null)
                {
                    objClass1 = new T1();
                }
 
                return objClass1;
            }
        }
    }

No comments:

Post a Comment