在C#的继承类中使用强制性实现对类进行重载构造函数 [英] make a overloaded constructor of a class with mandatory implementation in the inherited class in c#

查看:82
本文介绍了在C#的继承类中使用强制性实现对类进行重载构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在c#的继承类中使类的重载构造函数具有强制性实现

具有构造函数A(字符串A1,字符串A2)的A类


B类继承了A类

在这个继承的类中,我想强制实现基本构造函数A(字符串A1,字符串A2)

如果在继承的类中未使用此方法,则对于类B应该出现编译错误.


预先感谢您的帮助

谢谢
Venkat

Make a overloaded constructor of a class with mandatory implementation in the inherited class in c#

Class A with constructor A(string A1, string A2)


Class B inherits class A

In this inheriting class I want to mandate the implementation of the base constructor A(string A1, string A2)

If this is not used in the inheriting class compilation error should come for class B.


Thanks in advance for the help

Thanks
Venkat

推荐答案

您不能像方法重载那样强制执行它,因为构造函数不会被继承.同样,如果您尝试根据上面的示例编译new B ("Foo", "Bar"),则会出现编译错误,因此在大多数情况下(例如,非反射和非动态(在C#4方面)),此代码不应一个问题.
You can''t mandate it like you can with a method overload, as constructors are not inherited. Equally, if you try and compile new B ("Foo", "Bar") against your example above, you''ll get a compile error, so in most circumstances (e.g. non-reflective and non dynamic (in the C# 4 sense) code this shouldn''t be a problem.


构造函数不能是抽象的





; P
Constructors can''t be abstract





;P


这篇关于在C#的继承类中使用强制性实现对类进行重载构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆