C# 利用泛型创建有参对象

        /// 
        /// 利用泛型创建对象
        /// 
        /// 
        private T NewObj() where T : class
        {
            Session session = EstateConHandler.Instance.TargetSession;
           
            T rt = Create(session);

            return rt;
            
        }
        static T Create(Session session)
        {
            return (T)Activator.CreateInstance(typeof(T), new object[] { session });
        }


        private T NewObj() where T : class
        {
            string str = "fsdfs";
           
            T rt = Create(str);

            return rt;
            
        }
        static T Create(string str)
        {
            return (T)Activator.CreateInstance(typeof(T), new object[] { str});
        }



       ``` 

你可能感兴趣的:(C# 利用泛型创建有参对象)