Collection of objects C #

0

I need to populate a list that is inside another list, but it is giving error.

Follow the code:

Promotora = new LojaPromotoraInfo 
            { 
                CodGerente = DBUtil.GetValor<string>(oRow, "CodGerente"), 
                CodLojaPromotora = DBUtil.GetValor<string>(oRow["CodLojaPromotora"]),
                Agente = new List<PropostaAgente>()
                {

                }

            },

Properties within Agente do not appear because Agente is IList .

How can I fill it out?

Thank you

    
asked by anonymous 13.03.2016 / 14:16

1 answer

0

See the example below;

This is a webforms application, but you only need to understand the part of classes and what you have inside the Page_Load method.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication1
{
    public partial class _Default : Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var addlista = new List<PropostaAgente>();

            var lista1 = new PropostaAgente()
            {
                Campo1 = "Campo1",
                Campo2 = "Campo2",
            };

            addlista.Add(lista1);

            var Promotora = new LojaPromotoraInfo
            {
                CodGerente = "CodGerente",
                CodLojaPromotora = "CodLojaPromotora",
                Agente = addlista,
            };

            var teste = Promotora;
        }
    }

    public class LojaPromotoraInfo
    {
        public List<PropostaAgente> Agente { get; internal set; }
        public string CodGerente { get; internal set; }
        public string CodLojaPromotora { get; internal set; }
    }

    public class PropostaAgente
    {
        public string Campo1 { get; internal set; }
        public string Campo2 { get; internal set; }
    }
}

You can change addlista by a method that returns this list or only informs the list if you already have it.

    
13.03.2016 / 14:56