I created a method that has two lists; each one has four tuples, and I want the two lists to be returned when the method is called. I tried creating a new list to do so, but it can't accept a tuple into a list. Is there a way to convert a tuple into a list?
How should I create a list that'll be returned when method is called and it contains two lists, each one contains four tuples?
Below is a code similar to what I'm working on:
*Note: the reason I needed to use tuples is to be able to access and display them using XAML
.
var listStudents1 = new List<Tuple<string, string, string>>
{
Tuple.Create("A", "Roya Taymoor", "USA"),
Tuple.Create("B", "Michael Stevens", "UK" ),
Tuple.Create("C", "Steve Barnes", "UK" )
};
var listStudnets2 = new List<Tuple<string, string, string>>
{
Tuple.Create("C", "Liam Cook", "USA"),
Tuple.Create("D", "Arianda Reggi", "France" ),
Tuple.Create("E", "Amy Ronald", "UK" )
};
StudentsLists.Add(listStudents1); //StudentsLists is a previously defnded property/list in the class that accepts string.
StudentsLists.Add(listStudents2);
return StudentsLists;
Just use List<whateverYouWantToReturn>
in your case like this below one.
public List<List<Tuple<string, string, string>>> GetStudents(){
var listStudents1 = new List<Tuple<string, string, string>>
{
Tuple.Create("A", "Roya Taymoor", "USA"),
Tuple.Create("B", "Michael Stevens", "UK" ),
Tuple.Create("C", "Steve Barnes", "UK" )
};
var listStudnets2 = new List<Tuple<string, string, string>>
{
Tuple.Create("C", "Liam Cook", "USA"),
Tuple.Create("D", "Arianda Reggi", "France" ),
Tuple.Create("E", "Amy Ronald", "UK" )
};
var result = new List<List<Tuple<string, string, string>>>();
result.Add(listStudents1);
result.Add(listStudnets2);
return result;
}