Inline Method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sahil Malik [MVP]

    Inline Method

    Is there a way to do Inline methods in C# - like you can in C++?

    If not, can anyone tell me the reasoning behind why they were removed?

    - Sahil Malik [MVP]





  • Jeff Connelly

    #2
    Re: Inline Method


    "Sahil Malik [MVP]" <contactmethrum yblog@nospam.co m> wrote in message
    news:%23K1O$6sO FHA.3928@TK2MSF TNGP09.phx.gbl. ..[color=blue]
    > Is there a way to do Inline methods in C# - like you can in C++?
    >
    > If not, can anyone tell me the reasoning behind why they were removed?[/color]

    You cannot specify them directly. The main reason is that they were never
    guaranteed in C++ anyway. If you specify inline in C++, the compiler will
    do it if it can. On the other hand, the C# compiler will do it whenever it
    thinks it's best without you having to specify it. This results in
    optimized code (which is the point of inline functions anyway), but without
    the potential for slightly more control that you might have in C++. The end
    result is usually going to be better, since the optimal solution will almost
    always occur without any thought required on the programmers part.


    Comment

    • Bruce Wood

      #3
      Re: Inline Method

      Not to put too fine a point on it, but inlining is done by the JITter,
      not by the C# compiler.

      This allows the system to inline calls to simple methods / properties
      without locking method / property implementations into the compiled
      code (which would require you to recompile your application every time
      a DLL that you use changed).

      So, the inlining is done at run time when your code is translated from
      intermediate code to machine code (Just-In-Time compilation, or
      JITting).

      Comment

      • Sahil Malik [MVP]

        #4
        Re: Inline Method

        Okay Makes sense - thanks Bruce & Jeff.

        - Sahil Malik [MVP]





        "Bruce Wood" <brucewood@cana da.com> wrote in message
        news:1112812685 .732826.118000@ g14g2000cwa.goo glegroups.com.. .[color=blue]
        > Not to put too fine a point on it, but inlining is done by the JITter,
        > not by the C# compiler.
        >
        > This allows the system to inline calls to simple methods / properties
        > without locking method / property implementations into the compiled
        > code (which would require you to recompile your application every time
        > a DLL that you use changed).
        >
        > So, the inlining is done at run time when your code is translated from
        > intermediate code to machine code (Just-In-Time compilation, or
        > JITting).
        >[/color]


        Comment

        Working...