I have the following named list of Tuple
var tupleList = new List<(string SureName, string LastName, int Age)>();
How can I add items to that list using tupleList.Add ?
I have the following named list of Tuple
var tupleList = new List<(string SureName, string LastName, int Age)>();
How can I add items to that list using tupleList.Add ?
var tupleList = new List<(string SureName, string LastName, int Age)>();
tupleList.Add(("a", "b", 3));
As you can see it demanded an item at the end of add, which seems to be optional and the reason for the double brackets.
var tupleList = new List<Tuple<string, string, int>>();
tupleList.Add(new Tuple<string, string, int>("Nicolas", "Smith", 32));
Tuple
- the OP is asking about ValueTuple
, despite the title. (A "named tuple" always ends up meaning ValueTuple.) –
Zinc © 2022 - 2024 — McMap. All rights reserved.
("a", "b", 3)
is the syntax for a 3-item tuble. By adding whitespace, we can see the syntax more clearly:tupleList.Add( ("a", "b", 3) );
. Or we could split into two lines:var tuple = ("a", "b", 3); tupleList.Add(tuple);
– Naevus