i want to add in two set of strings to one list
i receive error that i cant use add
List<List<String>> lastmodified1 = new List<List<String>>();
lastmodified1.Add(new List<String>());
foreach (string filenamelocal in files)
{
string name = Path.GetFileName(filenamelocal);
lastmodified1[0][1].Add(Convert.ToString(filenamelocal));
lastmodified1[0][0].Add(Convert.ToString(File.GetLastAccessTime(filenamelocal)));
}
you target the list with the first index
lastmodified1[0].Add(Convert.ToString(filenamelocal));
lastmodified1[0].Add(Convert.ToString(File.GetLastAccessTime(filenamelocal)));
with the index [0] you are target the list, because the first List is implicit. so with
lastmodified1[0].Add(Convert.ToString(filenamelocal)); //this is accessing to the List inside the First list
you are accesing to the second List inside from the first List. with the second index you're accessing to the value of the second list, in this case String, and you can get the method add because strings dont have
lastmodified1[0][0] //this access to string value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With