Simple C# Noop Statement

后端 未结 15 766
面向向阳花
面向向阳花 2021-02-01 01:14

What is a simple Noop statement in C#, that doesn\'t require implementing a method? (Inline/Lambda methods are OK, though.)

My current use case: I want to occupy the c

15条回答
  •  滥情空心
    2021-02-01 02:05

    This is an addition to @AHM 's answer since I wanted an easy way to do NOOP for debugging purposes (communicating with AB PLC CompactLogix and ran into errors only really visible in Disassembly because of C++ library DLL import in C#).

    I took the one-liner

    ((Action)(() => { }))();
    

    and put it into a snippet named noop.snippet then placed it in the folder named My Code Snippets.
    (Tools -> Code Snippets Manager -> Location) OR Chord (Ctrl+K,Ctrl+B)

    
    
        
            
    noop noop Code snippet to inject an assembly (x86) equivalent of the NOOP command into the code's disassembly. Jay Whaley Expansion
    { }))(); $end$]]>

    This helps to make it a quick use shortcut in case low level communication becomes muddled and requires this to be a common debugging tactic. The actual assembly generated is as follows, but there're some posts about how to use actual assembly inline in C#.

提交回复
热议问题