Search code examples
c#listxamarin.formsienumerablepicker

How to read IEnumerable List values one by one in Xamarin forms?


I need to read a List that has two properties, one is an ID int, the other is string. After I get the values into the list I don't know how to break them down to the the IDs and name string one by one.

This is what I've got:

private async void UpdatePisterosLocal(List<Pisteros> PisterosLista)
        {
            try
            {
                PisterosDBController pistDB = new PisterosDBController();
                Pisteros_Local pistLocal = new Pisteros_Local();

                //this is my code trying to read the list PisterosLista
                foreach (string element in PisterosLista)
                {
                    pistLocal.IDPistero = //don't know what to write here
                    pistLocal.PisteroN = //and here
                }
                
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Solution

  • This how I finally did it

    foreach (var item in PisterosLista)
            {
                var DatosRegistro = new T_Pisteros
                {
                    PisteroID = item.PisteroID,
                    PisteroN = item.PisteroN
                };
                var num = db.Insert(DatosRegistro); //insert into new DB
            }