How to change value of an object using linq

前端 未结 4 1202
半阙折子戏
半阙折子戏 2021-01-23 14:10

I have the following statment that if isdefault is true to this collection i need to set each object isDefault property to false.

  custHead.lstCustomziation.Whe         


        
4条回答
  •  猫巷女王i
    2021-01-23 14:30

    Linq may have been initially created for querying but it has evolved and is used as functional programming methods, equivalents to "map", "reduce", and "filter" used in other languages.

    In your example I would suggest:

    var list = custHead.lstCustomziation.Where(x => x.IsDefaultSelected == true)
                .Select(x=> TransformItem(x));
    
    private XType TransformItem(XType item){
        item.IsDefaultSelected=false;
        return item;
    }
    

提交回复
热议问题