new tuple syntax c# code example

Example 1: c# tuple

// How to create a Typle
Tuple<int, string, string> person = 
                        new Tuple <int, string, string>(1, "Steve", "Jobs");

//extra examples
var person = Tuple.Create(1, "Steve", "Jobs");
person.Item1; // returns 1
person.Item2; // returns "Steve"
person.Item3; // returns "Jobs"


var numbers = Tuple.Create("One", 2, 3, "Four", 5, "Six", 7, 8);
numbers.Item1; // returns "One"
numbers.Item2; // returns 2
numbers.Item3; // returns 3
numbers.Item4; // returns "Four"
numbers.Item5; // returns 5
numbers.Item6; // returns "Six"
numbers.Item7; // returns 7
numbers.Rest; // returns (8)
numbers.Rest.Item1; // returns 8

Example 2: c# tuple

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