1

I need to access last-inserted Key inside the Dictionary, I do not know the name of it.

int LastCount = mydict[mydict.keys[mydict.keys.Count]];

It does not work because Dictionary.Keys does not implement indexer.

if there is any way, essentially a Dictionary that implements an []-indexer on the Keys?

MD. RAKIB HASAN
  • 3,670
  • 4
  • 22
  • 35

1 Answers1

3

No. There is no such thing as a "last inserted key".

The documentation specifically says:

The order of the keys in the Dictionary<TKey,TValue>.KeyCollection is unspecified

You will have to modify the piece of code that inserts into the dictionary and keep track of the last inserted value there.

nvoigt
  • 75,013
  • 26
  • 93
  • 142