How to retrieve actual item from HashSet?

前端 未结 11 577
花落未央
花落未央 2020-12-02 17:55

I\'ve read this question about why it is not possible, but haven\'t found a solution to the problem.

I would like to retrieve an item from a .NET HashSet. I

11条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 18:40

    Ok, so, you can do it like this

    YourObject x = yourHashSet.Where(w => w.Name.Contains("strin")).FirstOrDefault();
    

    This is to get a new Instance of the selected object. In order to update your object, then you should use:

    yourHashSet.Where(w => w.Name.Contains("strin")).FirstOrDefault().MyProperty = "something";
    

提交回复
热议问题