How do I return a single object with an array and a list?

I have a list and an array that I would like to return, but I'm not sure how to bring them together. I deserialized my JSON and created two objects. How can I combine this list and array into one object?

var one = JsonConvert.DeserializeObject<MyData.RootObject>(first);
var two = JsonConvert.DeserializeObject<MyData.RootObject>(second);

List<myData.DataOne> listOne = new List<myData.DataOne>();

foreach (var items in one) 
{
     someDataModel model = new someDataModel();
     model.property = one.rows.f[0].v;
     listOne.Add(model);
}

string[] array = new string[two.rows.Count];

        for (var items = 0; items < two.rows.Count; items++)
        {
            array[items] = two.rows[items].f[0].v;
        }

return null;

      

+3


source to share


2 answers


Create a new class to represent a combination of these two pieces of data:

public class MyReturnType 
{
    public List<myData.DataOne> ListOne {get;set;}
    public string[] Array {get;set;}
}

      



Then return it:

return new MyReturnType {ListOne = listOne, Array = array};

      

+3


source


Create a tuple with types like List <> and string [].



var tupleObject = new Tuple<List<myData.DataOne>, string[]>(listOne, array);
return tupleObject;

      

+2


source







All Articles