locked
Change ToDictionary to ToList RRS feed

  • Question

  • Hello,

    I have the following code:

       return _resources.Root.Elements("Resource").Select(r => new Resource {
        Id = (Int32)r.Element("Id"),
        Constraints = _resourcesConstraints.Root.Elements("ResourceConstraint")
         .Where(rc => rc.Element("ResourceId").Value == r.Element("Id").Value)
         .ToDictionary(rc => (Int32)rc.Element("ConstraintId"), rc => (String)rc.Element("Value")),
       });


    I want to change the Constraints property from IDictionary to IList<Constraint>.

    Each constraint object has 2 properties: Id and Value.

    So I need to change the code line:
    .ToDictionary(rc => (Int32)rc.Element("ConstraintId"), rc => (String)rc.Element("Value")),

    ToList > and create a List of Constraint filling the Id and Value of the constraint the same way.

    How can I do this?

    Thank You,
    Miguel
    Wednesday, April 28, 2010 9:15 PM

Answers

  • .ToList(rc => new Constraint { Id = (Int32)rc.Element("ConstraintId"), Value = (String)rc.Element("Value") }),
    • Proposed as answer by bingelp Thursday, April 29, 2010 12:25 AM
    • Marked as answer by Harry Zhu Wednesday, May 5, 2010 4:45 AM
    Thursday, April 29, 2010 12:21 AM