• 0

[C#] ConcurrentDictionary.ContainsKey() Exception


Question

ok so the exception throw is pretty self-explanitory, I could fix this with Try-Catch but I want to understand why in the hell ContainsKey is throwing an exception rather than a boolean like the documentation states. It was my understanding that the whole purpose of that function was to return false if it didn't exist in the dictionary.

if (colListUnitType.ContainsKey(colInventoryWarehouseItem[12]) == true) {

I have also tried just

if (colListUnitType.ContainsKey(colInventoryWarehouseItem[12])) {

As I said, my expected behavior is ContainsKey() to return a boolean like the documentation states but instead I'm getting an exception ("KeyNotFoundException was unhandled by user code: The given key was not present in the dictionary.").

-- Solution was that I had legacy code still laying around with references to stuff that didn't exist anymore and had changed.

Edited by FuhrerDarqueSyde

1 answer to this question

Recommended Posts

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.