none
Update List Element's multiple properties RRS feed

  • Question

  • I have a  List<T> need update several properties. I am using the following statement to update one property. Is that possible one statement updating multiple properties?

      (lstObjects.Where(row => row.id == idParameter || row.Time == specificTime)).ToList().ForEach(
                    row => row.parm1=parameterValue);
    Thursday, June 2, 2011 8:45 PM

Answers

  • Hi,

    Yes, you must use a delegate:

     (lstObjects.Where(row => row.id == idParameter || row.Time == specificTime))
          .ToList()
          .ForEach(delegate(Object row)
          {
              row.parm1=parameterValue1;
              row.parm2=parameterValue2;
          });
    
    

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    • Marked as answer by TravelMan Thursday, June 2, 2011 9:57 PM
    Thursday, June 2, 2011 9:16 PM

All replies

  • Hi,

    Yes, you must use a delegate:

     (lstObjects.Where(row => row.id == idParameter || row.Time == specificTime))
          .ToList()
          .ForEach(delegate(Object row)
          {
              row.parm1=parameterValue1;
              row.parm2=parameterValue2;
          });
    
    

    Regards,

    JA Reyes.


    Please remember to Vote & "Mark As Answer" if this post is helpful to you.
    Por favor, recuerda Votar y "Marcar como respuesta" si la solucion de esta pregunta te ha sido útil.
    • Marked as answer by TravelMan Thursday, June 2, 2011 9:57 PM
    Thursday, June 2, 2011 9:16 PM
  • That helps. Thanks
    Thursday, June 2, 2011 9:57 PM