How to traverse a dictionary without foreach that creates boxing?

How to traverse a dictionary without foreach that creates boxing?

I think that kind of question is better placed on stackoverflow

You have to get the Enumerator yourself, it doesn’t create any garbage since the Enumerator is a struct. Foreach boxes it and creates garbage.

// Doing a foreach boxes the enumerator, calling it explicitly doesn't.
var enumerator = myDictionary.GetEnumerator();
while (enumerator.MoveNext())
{
	Debug.Log(enumerator.Current.Key);
}
enumerator.Dispose();