简体   繁体   English

如何将空参数传递给基类构造函数C#

[英]how to pass null arguments to base class constructor c#

I have two class which extends a base class and baseclass takes 5 argument but in two of my derived class I don't want to pass 5 arguments . 我有两个扩展基类的类,而基类需要5个参数,但是在我的两个派生类中,我不想传递5个参数。 can anyone tell me how to bypass it . 谁能告诉我如何绕过它。 I'm new at this . 我是新来的。 please help 请帮忙

Example : 范例:

BaseClass BaseClass的

    public abstract class xyz<TOrderView, Component1, Component2, Component3, Component4>        

Derived class 1 派生类1

    public class abcdef : xyz<IOrderView, Component1, Component2, Component3>

Derived class 2 public class rdesa : xyz 派生2类公共类rdesa:xyz

Class abcdef doesn't need 5 argument but class rdesa need to pass 5 argument . abcdef类不需要5个参数,但rdesa类需要传递5个参数。 Can anyone tell me how to pass null as argument to base class . 谁能告诉我如何将null作为参数传递给基类。 I'm new at this please help . 我是新来的,请帮忙。

Long answer: 长答案:

You need to re-examine your inheritance hierarchy after reading up on the Liskov substitution principle. 阅读了Liskov替换原理后,您需要重新检查继承层次结构。

Short answer: You can pass some acceptable type to the base class constructor. 简短的答案:您可以将一些可接受的类型传递给基类构造函数。

public class abcdef<IOrderView, Component1, Component2, Component3> 
    : xyz<IOrderView, Component1, Component2, Component3, object>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM