Return a class with two properties from one method

0

Good I'm doing a function that returns two results.

I have been doing but I get error error could help me.

the code is as follows:

public entidadd  calcular()
{
 return new Double[] {2,3};
}

public class entidadd
{
double numero1;
dpuble numero2;
}

    
asked by PieroDev 07.11.2018 в 19:15
source

2 answers

2

Dear, entity is a class, and you try to return an array of Double, your function should be like this:

public entidadd  calcular()
{
    entidadd ret = new entidadd();
    ret.numero1 = 2;
    ret.numero2 = 3; 
    return ret;
}

public class entidadd
{
    public double numero1 { get; set; }
    public double numero2 { get; set; }
}

Greetings!

    
answered by 07.11.2018 / 19:20
source
2

You can use tuple, I'll give you an example:

public Tuple<double, double> GetMultipleValue()
{
    return Tuple.Create(1.0,2.0);
}

and to access the values you use item1 and item2 for example:

var x = GetMultipleValue();
double i1 = x.item1;
    
answered by 07.11.2018 в 19:19