How can I search a list for two different things?
For example, this code works perfectly fine:
int index = mylistofobjects.FindIndex(a => a.firstname == "Bob");
Is there a way to change it to something like this?
int index = mylistofobjects.FindIndex(a => a.firstname == "Bob", a.lastname == "Smith");
I'm trying to return the mylistofobjects instance that has first name Bob and lastname Smith.
Thanks for the help.
Try this:
int index = mylistofobjects.FindIndex(a => a.firstname == "Bob"&& a.lastname == "Smith");
Use && operator.
int index = mylistofobjects.FindIndex(a => a.firstname == "Bob" && a.lastname == "Smith");
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