Click here to Skip to main content
15,918,976 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had referenced at MSDN and found the register keyword, but it's only in C++.
Syntax:
C++
register int x = 0;

Can you tell me how to do that with C#?

Thanks!
Posted

1 solution

You don't.

Even in C++, the register keyword is only a suggestion. The compiler is free to ignore it.
http://stackoverflow.com/questions/3207018/register-keyword-in-c[^]

In C#, you're not compiling to machine code; you're compiling to MSIL. The JIT compiler later compiles the MSIL to machine code, applying various optimizations to make your code run faster on the current hardware. Adding the register hint to a C# variable would be entirely pointless.
 
Share this answer
 
Comments
[no name] 3-Oct-14 17:34pm    
5. Deleted my answer imediatelly after reading yours ;)
Andreas Gieriet 3-Oct-14 18:06pm    
My 5 too!
Cheers
Andi
Sergey Alexandrovich Kryukov 4-Oct-14 8:09am    
Correct, a 5.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900