define tuple c# in function code example

Example 1: c# tuple

var tupleList = new List<Tuple<int, string, string, string>>();
 tupleList.Add(Tuple.Create(1, "Sefat Anam", "Dhaka Bangladesh", "0.1245345"));

Example 2: tuple parameter name

// Tuples cannot be assigned parameter names.
//Instead you could do something like this:

(string name, int id) user = ("jack", 1);
Console.WriteLine($"{user.name}, {user.id}");
// Output:
//	jack, 1

// When working with lists:

List<(string name, int id)> users = new List<(string, int)>();

users.Add(("jack", 1));
users.Add(("john", 2));

users.ForEach((x) =>
	Console.WriteLine($"{x.name}, {x.id}")):

// Output:
//	jack, 1
//	john, 2