Ivan Kochurkin
Ivan Kochurkin

Reputation: 4481

Duplication top of stack item in IL without helper variable

Is it possible to copy top stack item and push it back? I only know about solution with using of helper local variable like this:

stloc.n
ldloc.n
ldloc.n 

Are IL instructions for copying stack items exist? Is it possible to avoid using of helper local variable?

Upvotes: 1

Views: 162

Answers (1)

Marcus
Marcus

Reputation: 6117

Did you look at OpCodes.Dup, it duplicates the top stack item?

Upvotes: 5

Related Questions