How to create a list of objects?

Asked

Viewed 53 times

0

Good afternoon, I’m developing a project. NET Core Razor Pages and in it I will need to create and add items in a list... these items are strings and are extracted from an XML.

I’ll leave a part of my code below, which is where I want the items to be added to this list of objects.

var descricao = "";
int i = 1;
while (result.vfp.row[i].men == "_MSYSMENU")
{
    descricao += result.vfp.row[i].des;
    i++;
}

So this descricao that would be my list, and every time I walked by, I added an item to my list.

  • And what is this list? How will it be used? What requirements? Give more details.

  • Next, I need to assemble this list with the XML data, (which from the answers I already have, I am mounting) and I will use to assemble a menu (<nav>). Now I will need to use the list to create each menu option, in html @Maniero

1 answer

0


If it’s just String you can use:

List<string> nomeDaLista = new List<string>();
nomeDaLista.add(result.vfp.row[i].des);

Apparently your code has some strange things.

The object result is what? a DataTable?

If so, why not wear it like this:

List<string> nomeDalista = new List<string>();

DataTableReader reader = result.CreateDataReader();

if(reader.HasRows)
{
    while(reader.Read())
    {
          if(reader["men"].ToString() == "_MSYSMENU")
             nomeDalista.Add(reader["des"].ToString());
    }
}
  • 1

    I’m sorry, but result is not a Datatable, result is where I do the Deserialize of a JSON, but thanks for the reply, I’ve already managed to create the list

Browser other questions tagged

You are not signed in. Login or sign up in order to post.