Search for Object in Generic List

前端 未结 4 1711
生来不讨喜
生来不讨喜 2020-12-08 22:17

Is it possible to search for an object by one of its properties in a Generic List?

Public Class Customer

    Private _id As Integer

    Private _name As St         


        
4条回答
  •  执念已碎
    2020-12-08 23:19

    If you are using .NET 3.5 this can be done with LINQ to Objects:

    How to: Query an ArrayList with LINQ

    If not, in .NET 2.0 you can use the Find method of the list.

    The idea is that you will need to provide an method that return true if a property of your object satisfies a certain condition.

提交回复
热议问题