class Object
{
public int ID {get; set;}
public string description {get; set;}
}
If I have a List<Object> Objects
populated with various objects, and I want to find objects whose description is something particular, how would I do that?
find every Object in Objects whose description == "test"
One can use filter() function in JavaScript to filter the object array based on attributes. The filter() function will return a new array containing all the array elements that pass the given condition. If no elements pass the condition it returns an empty array.
Python has a built-in function called filter() that allows you to filter a list (or a tuple) in a more beautiful way. The filter() function iterates over the elements of the list and applies the fn() function to each element. It returns an iterator for the elements where the fn() returns True .
keys() to filter an Object. After you've generated the keys, you may use filter() to loop over the existing values and return just those that meet the specified criteria. Finally, you can use reduce() to collect the filtered keys and their values into a new object, for instance.
You can use LINQ:
var results = Objects.Where(o => o.Description == "test");
On a side note, realize that Object
is a very poor choice of names for a class, and won't even compile as-is... I'd recommend choosing more appropriate names, and following standard capitalization conventions for C#.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With