-1

In my code:

decimal maxPrice = list.Max(i => i.price);

Getting error - Object reference not set to an instance of an object. NullReferenceException was unhandled by code.

The i value becomes null, though the list count is 6709. How do I resolve this?

user1254053
  • 705
  • 2
  • 17
  • 48

1 Answers1

2

So your list contains nulls.

Either filter them: list.Where(l => l != null).Max(...), or prevent the nulls to end up in the list in the first place.

CodeCaster
  • 131,656
  • 19
  • 190
  • 236