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.

bilpor
  • 3,467
  • 6
  • 32
  • 77
  • 7
    [Dictionary.TryGetValue(TKey, TValue) Method](https://learn.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.trygetvalue?view=netframework-4.8) – A Friend Jun 26 '19 at 12:45
  • 1
    Your `get` can't return 0. I suppose it could return a `Dictionary` that has a key and value of 0, but that's not the same thing. – Jim Mischel Jun 26 '19 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 – bilpor Jun 26 '19 at 12:50
  • @bilpor We could help more if you could provide a [mcve]. – mjwills Jun 26 '19 at 12:56

0 Answers0