1

I have the following:

public static Dictionary<int,int> IdToDbIdMap { get => (Dictionary<int, int>Cx.FixedData[nameof(Cx0.IdToDbIdMap)]; set => Cx.SetFixed(nameof(Cx0.IdToDbIdMap), value); } 

The issue I have is that if the key doesn't exist in the dictionary, then it crashes with 'keyNotFound' exception. How can I change the above to return 0 if not found.

4
  • 7
    Dictionary<TKey,TValue>.TryGetValue(TKey, TValue) Method Commented Jun 26, 2019 at 12:45
  • 1
    Your get can't return 0. I suppose it could return a Dictionary<int, int> that has a key and value of 0, but that's not the same thing. Commented Jun 26, 2019 at 12:48
  • Hi @JimMischel returning dictionary<0,0> would work for me, but Im having difficulty changing the getter on, this. It's someone elses code that I've had to pick up. I've tried forcing a TryGetValue onto the call, but no luck Commented Jun 26, 2019 at 12:50
  • @bilpor We could help more if you could provide a minimal reproducible example. Commented Jun 26, 2019 at 12:56

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.