none
Need to create new instance for every item in List RRS feed

  • Question

  • Hi,

    I have a List containing objects. I need to set the value as this object in a for loop

    foreach (FieldValueEntry fv1 in fieldvalueentries)
    {

    filterSelection.FieldValues = new[] { fv1 };

    }

     By doing this I know only the last value in the list will be assigned. But I want to dynamically create FieldValues and assign it to filterSelection.

    Any help please?

    Tuesday, April 3, 2018 10:59 AM

All replies

  • You didn't provide any type information so we aren't going to be of much use. Do you have multiple filterSelection instances? Is it an array?

    If you're trying to set FieldValues to the list of fieldvalueentries then just do this.

    //Assuming fieldvalueentries is of type IEnumerable<T> 
    filterSelection.FieldValues = fieldvalueentries.ToArray();


    Michael Taylor http://www.michaeltaylorp3.net

    Tuesday, April 3, 2018 1:56 PM
    Moderator
  • Hi Michael,

    .ToArray() did the trick. Thank you very much.

    Regards,

    TSB

    Tuesday, April 3, 2018 4:12 PM
  • Hello tsbalaji,

    Don't forget to mark the helpful reply as answer if the issue has been solved. This can be beneficial to other people that has the same situation. And if you have any concerns, please do not hesitate to let us know.

    Best regards,

    Neil Hu


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, April 4, 2018 3:05 AM
    Moderator