2D List Of String?

S-Soft 666 Reputation points
2022-11-27T22:52:30.68+00:00

Hello,
I didn't learn LINQ, but am given this code:

        Dim MyResult As List(Of String) = MyXDocument.Root _  
            .Elements(MyXSpace + "category") _  
            .Select(Function(c) c.Attribute("name").Value & " :: " & c.Attribute("color").Value) _  
            .ToList()  

This saves xml node name & color in a single field like:

nameX :: colorBlue

I'd like to save them in a 2D List Of String, not sure if this the correct definition (so won't have to split it again later):

Dim MyResult As List(Of List(Of String))

And then how to write the .Select line to save c.Attribute("name").Value and c.Attribute("color").Value each one in a dimension of List?

Developer technologies | VB
Developer technologies | C#
{count} votes

Accepted answer
  1. Bruce (SqlWork.com) 77,766 Reputation points Volunteer Moderator
    2022-11-28T23:30:24.197+00:00

    don't know vb, but in C# it would be:

     var MyResult = MyXDocument.Root  
                 .Elements(MyXSpace + "category")  
                 .Select(c => new List<string>   
                 {  
                       c.Attribute("name").Value,   
                       c.Attribute("color").Value  
                 })  
                 .ToList();  
    

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.