How to return 2 array of values

Posted by Oswaldlily under C# on 12/12/2011 | Points: 10 | Views : 2498 | Status : [Member] | Replies : 1
How to return 2 array of values...follwing return gives me error

public int calculate(List<list1> listnew
{
for (int i = 0; i<= (listnew.Count() - 1); i++)
{

int[] result = new int[] { };
int[] result1 = new int[] { };
result[i] = listnew[i].a;
result1[i] = listnew[i].b;
return result[i],result1[i];
}

}




Responses

Posted by: Blessyjees on: 12/12/2011 [Member] Bronze | Points: 25

Up
0
Down
Hi,

Your function return type is "int" so you can't return array. For retrun two array at the time time, you can try dictionary object. Add your array to dictionary object's kay pair and return this.

public Dictionary<object, object> calculate(List<list1> listnew
{
for (int i = 0; i<= (listnew.Count() - 1); i++)
{
Dictionary<object, object> arraylist =
new Dictionary<object, object>();
int[] result = new int[] { };
int[] result1 = new int[] { };
result = listnew.a;
result1 = listnew.b;
arraylist.Add("array1",result);
arraylist.Add("array2:, result1);

return arraylist;
}


}


Blessy Baby
Digitalmesh Softech pvt Ltd
https://blessybaby.wordpress.com/

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response