Return one of two possible objects of different types sharing a method

前端 未结 6 1651
悲哀的现实
悲哀的现实 2020-12-06 05:12

I have 2 classes:

public class Articles
{
    private string name;

    public Articles(string name)
    {
        this.name = name;
    }

    public void O         


        
6条回答
  •  清歌不尽
    2020-12-06 05:43

    You have 3 choices:

    1) Make Questionnaire and Article inherit from the same base class and make the type of that base class be the return type of your method.

    2) Make your return type Object.

    3) Make your return type Dynamic.

提交回复
热议问题