Search list of objects based on object variable

后端 未结 4 763
独厮守ぢ
独厮守ぢ 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 15:00

    Sounds like a job for LINQ!

    var matchedObject =
       from t in TextPool
       where t.UName == "test"
       select t;
    

    This is assuming your search is defined in code. If your code is driven by the UI, you may simply need to do a linear iteration. To search all possible attributes, without indexing, it isn't going to get any faster.

    [ Edit: Was beaten to the punch, but leaving this up as an example of a different syntax, plus a link ]

提交回复
热议问题