I have the following code and it seems to work fine, but when I inspect the tuples inside the list they are named Item1,Item2,Item3 instead of the names I have assigned to them. What am I doing wrong? (The code references System.ValueTuple.)
Thank you for your help.
var listContent = new List<(string date, double value, DateTime datetime)>();
// Read the file just created and put values in list of tuples
using (var reader = new StreamReader(rawFileName))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
var values = line.Split(',');
listContent.Add((date: values[0],
value: Convert.ToDouble(values[2]),
datetime: DateTime.ParseExact(values[0], "yyyy-MM-dd", null)));
}
}
If I put a breakpoint just after the above code, in the Immediate Window I can do the following, which is even more puzzling:
listContent[0]
("2017-01-01", 17.193, {01/01/2017 00:00:00})
date: "2017-01-01"
value: 17.193
datetime: {01/01/2017 00:00:00}
Raw View: ("2017-01-01", 17.193, {01/01/2017 00:00:00})
listContent[0].Item1
null
listContent[0].date
null
listContent[0].dummy
error CS1061: '(string date, double value, DateTime datetime)' does not contain a definition for 'dummy' and no accessible extension method 'dummy' accepting a first argument of type '(string date, double value, DateTime datetime)' could be found (are you missing a using directive or an assembly reference?)
[UPDATE]
I have super-simplified the code:
var listContent = new List<(string str1, string str2)>();
for (var n = 1; n < 100; n++)
{
var tpl = (str1: "hello" + n.ToString(), str2: "world" + n.ToString());
listContent.Add(tpl);
}
var z = listContent[0].str1;
and check out what the immediate window gives me:
z
"hello1"
listContent[0].str1
null
So I'm not going crazy: the tuples are assigned correctly but for some bizarre reason the immediate window still gives me null for listContent[0].str1 ???