所以我稍微看了一下MethodImplAttribute,我遇到了MethodImplOptions.AggressiveInlining,它被描述为:
如果可能,应该内联该方法.
Oooooh,我心里想,这听起来很有趣 - 我可以假装我比编译器更聪明,强制代码只使用我的邪恶意志的力量和几个方括号,ha,ha,ha ...
因此,我启动了Visual Studio 2013,创建了一个控制台应用程序,将.NET版本设置为4.5.1并编写程序以结束所有程序(Release当然,在模式下编译它):
using System;
using System.Runtime.CompilerServices;
namespace ConsoleApplication1
{
public static class SoHelpful
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static int GetSomeValueProbablyTwelve()
{
return 12;
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static int GetSomeValueLikelyThirteen()
{
return 13;
}
public static int GetSomeValueMaybeItIsTwentyEight()
{
return 29;
}
}
class Program
{
static void Main()
{
int twelve = SoHelpful.GetSomeValueProbablyTwelve();
int thirteen = SoHelpful.GetSomeValueLikelyThirteen();
int twentyNine = SoHelpful.GetSomeValueMaybeItIsTwentyEight();
Console.WriteLine((twelve + thirteen + twentyNine));
}
} …Run Code Online (Sandbox Code Playgroud)