473,396 Members | 2,024 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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]
http://codebetter.com/blogs/sahil.malik/


Nov 17 '05 #1
3 5777

"Sahil Malik [MVP]" <co*****************@nospam.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
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?


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.
Nov 17 '05 #2
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).

Nov 17 '05 #3
Okay Makes sense - thanks Bruce & Jeff.

- Sahil Malik [MVP]
http://codebetter.com/blogs/sahil.malik/


"Bruce Wood" <br*******@canada.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
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).

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: sks_cpp | last post by:
I want to inline a function operator (part of a functor class) that does a push_back on a list container. Would the compiler inline this method or not? How can I tell? Since the method...
2
by: Jeff Williams | last post by:
The common method of defining template classes and functions is to put the definition and declaration into the same header file. Or at least I believe it to be the common method and it is...
13
by: A | last post by:
Hi, I'm having problems completing a project in C++. I have been using inline functions in some of my header files. I have only done so for simple functions that only have 1 statement (eg....
20
by: qazmlp | last post by:
My class in a header file, contains inline virtual destructor. Is this Ok? Can it cause any problems? class base { public: base() { } virtual ~base { std::cout<<"Inside virtual destructor\n";...
3
by: Dave | last post by:
Hello all, I have one method of a class calling another method (both private, though that shouldn't matter). The method and its enclosing class are declared in a .h file and the method is...
6
by: RainBow | last post by:
Greetings!! I introduced the so-called "thin-template" pattern for controlling the code bloat caused due to template usage. However, one of the functions in the template happens to be virtual...
8
by: John Ratliff | last post by:
Can the compiler ever inline a method when there is a pointer to the member used? Thanks, --John Ratliff
6
by: ThomasR | last post by:
I was wondering on the breadth of optimization with .NET JIT compiler. Let's presume I have an assembly of static classes - mostly helper functions. Some of these functions may be very small...
15
by: niklaus | last post by:
Hi, I have a doubt regarding inline functions. 1) When does the inline of function happen. During the preprocessing stage or just before the object code is produced. Can we see the source code...
1
by: arjor | last post by:
hey guys When i try to make the following mutating method inline i get the following error: //method inline void vertex::setValue(int new_value) throw() { value_ = new_value; } error...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.