Search list of objects based on object variable

后端 未结 4 748
独厮守ぢ
独厮守ぢ 2021-02-13 14:30

I have a list of objects. These objects have three variables, ID, Name, & value. There can be a lot of objects in this list, and I need to find one based on the ID or Name

4条回答
  •  无人共我
    2021-02-13 14:50

    List TextPool = new List();
    objec found = TextPool.FirstOrDefault(item => item.Name == "test");
    if (found != null) found.value = "Value";
    

    If you are going to perform many lookups, you could cache the results in multiple Dictionary<> instances (or Lookup<> instance if keys are not unique).

提交回复
热议问题