How to disable parameterless constructor in C#

后端 未结 3 1849
时光取名叫无心
时光取名叫无心 2020-12-17 10:41
abstract class CAbstract
{
   private string mParam1;
   public CAbstract(string param1)
   {
      mParam1 = param1;
   }
}

class CBase : CAbstract
{
}
         


        
3条回答
  •  感情败类
    2020-12-17 11:25

    Please correct me if I am wrong, but I think I achieved that goal with this code:

    //only for forbiding the calls of constructors without parameters on derived classes
    public class UnconstructableWithoutArguments
    {
        private UnconstructableWithoutArguments()
        {
        }
    
        public UnconstructableWithoutArguments(params object[] list)
        {
        }
    }
    

提交回复
热议问题