C# program to access the generic Tuple list using Foreach Loop

Rajnilari2015
Posted by Rajnilari2015 under C# category on | Points: 40 | Views : 812
The below program will do so

//Create Generic Tuple Collection
List<Tuple<string, int, List<string>>> studentTupleInstances = new List<Tuple<string, int, List<string>>>();

//Add the first record
studentTupleInstances.Add(new Tuple<string, int,
List<string>>(
"Rajlakshmi Biswas", 4,
new List<string> { "Mathematics","English", "Science and Social Science","Hindi"}));

//Add the second record
studentTupleInstances.Add(new Tuple<string, int,
List<string>>(
"Niladri Biswas"
, 36
, new List<string> { "Mathematics","English","Computer Science","History","Physics"}));

//Add the third record
studentTupleInstances.Add(new Tuple<string, int, List<string>>(
"Arina Biswas"
, 26
, new List<string> { "Mathematics","English","Accountancy","Finance"}));


//Access the records using Foreach Loop
foreach(var student in studentTupleInstances)
{
Console.WriteLine("Student Name : " + student.Item1);
Console.WriteLine("Student Age : " + student.Item2);

foreach(var subject in student.Item3)
{
Console.WriteLine("Is reading : " + subject);
}

Console.WriteLine("------------------------------------------");
}

Comments or Responses

Login to post response