Why does generated IL code start with a Nop?

前端 未结 1 1788
小蘑菇
小蘑菇 2020-12-05 09:55

I was trawling through some of the IL of one of my assemblies (via ILDasm) and I noticed that all of my methods begin with a nop instruction.<

相关标签:
1条回答
  • 2020-12-05 10:37

    The assembly was compiled in debug mode. Nop instructions do not do anything (i.e have no side effects), but act as a convenient instruction to place a breakpoint.

    Tip

    If you need a place for an additional breakpoint for debugging purposes, you can force the inclusion of a Nop in a Debug build by adding a pair of empty braces, e.g.

    _grid.PreviewMouseRightButtonDown += (sender, e) =>
    {
        _isRightMouseDown = true;
    
        RowColumnIndex cell = _grid.PointToCellRowColumnIndex(e);
        {} //<------ Adding a Nop allows a breakpoint here.
    };
    
    0 讨论(0)
提交回复
热议问题