How to create a new object instance from a Type

后端 未结 12 1959
孤城傲影
孤城傲影 2020-11-22 03:26

One may not always know the Type of an object at compile-time, but may need to create an instance of the Type.

How do you get a new objec

12条回答
  •  野的像风
    2020-11-22 04:06

    public AbstractType New
    {
        get
        {
            return (AbstractType) Activator.CreateInstance(GetType());
        }
    }
    

提交回复
热议问题