Reputation: 17388
Can I include a check for null in this code:
var index = someList.FindIndex(p => p.Bla1.Id == Dto.Id || p.Bla2.Id == Dto.Id);
Bla1 and Bla2 can both be null. Thanks.
Upvotes: 2
Views: 1309
Reputation: 8850
Yes, you can =)
If you ask for how to do this:
var index = someList.FindIndex(p => (p.Bla1 != null && p.Bla1.Id == Dto.Id) || (p.Bla2 != null && p.Bla2.Id == Dto.Id));
But all depends on how you want to handle nulls
Upvotes: 0
Reputation: 85036
How about this:
var index = someList.FindIndex(p => (p.Bla1 != null && p.Bla1.Id == Dto.Id)
|| (p.Bla2 != null && p.Bla2.Id == Dto.Id));
Upvotes: 11