Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

add two strings to two dimensional list

Tags:

c#

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)));

        }
like image 427
Shay Rahamim Avatar asked Apr 08 '26 12:04

Shay Rahamim


1 Answers

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
like image 93
Black Hole Avatar answered Apr 11 '26 02:04

Black Hole



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!