C# Return Different Types?

后端 未结 15 2087
无人及你
无人及你 2020-12-08 09:11

I got something like this:

public [What Here?] GetAnything()
{
     Hello hello = new Hello();
     Computer computer = new Computer();
     Radio radio = ne         


        
15条回答
  •  忘掉有多难
    2020-12-08 09:49

    You could use external class, set the properties types as you wish, then use it in your function.

    public class MultipleOpjects
    {
        private List _ObjectOne;
        public List ObjectOne {
            get { return _ObjectOne; }
            set { _ObjectOne = value; }
        }
        private List _ObjectTwo;
        public List ObjectTwo {
            get { return _ObjectTwo; }
            set { _ObjectTwo = value; }
        }
        private object _ObjectThree;
        public object ObjectThree {
            get { return _ObjectThree; }
            set { _ObjectThree = value; }
        }
    }
    public MultipleOpjects GetAnything()
    {
        MultipleOpjects Vrble = new MultipleOpjects();
        Vrble.ObjectOne  = SomeThing1;
        Vrble.ObjectTwo = SomeThing2;
        Vrble.ObjectThree = SomeThing3;
    
        return Vrble;      
    }
    
        

    提交回复
    热议问题