Method should return multiple values

后端 未结 7 1071
执笔经年
执笔经年 2020-12-19 09:10

Hii

I have method in C#, I have to return multiple values from that method with out using collections like arrays. Is there any reliable way ?

7条回答
  •  时光说笑
    2020-12-19 09:24

    Yes could create a new type that will contain multiple properties and then return this type:

    public MyType MyMethod() 
    {
        return new MyType
        {
            Prop1 = "foo",
            Prop2 = "bar"
        };
    }
    

提交回复
热议问题