请考虑以下示例代码.
class Program
{
static void Main( string[] args )
{
DoSomethingWithAction( i =>
{
Console.WriteLine( "Value: {0}", i );
} );
Console.ReadLine();
}
private static void DoSomethingWithAction( Action<int> something )
{
Console.WriteLine( something.Target == null
? "Method is static."
: "Method is not static." );
something( 5 );
}
}
Run Code Online (Sandbox Code Playgroud)
如果我使用Visual Studio 2010(在CSC编译器下)编译并在Debug下运行此代码,它将打印出以下结果:
Method is not static.
Value: 5
Run Code Online (Sandbox Code Playgroud)
如果我在Visual Studio 2010中编译相同的代码,但这次使用Release设置,将生成以下输出:
Method is static.
Value: 5
Run Code Online (Sandbox Code Playgroud)
现在,如果我们要使用Visual Studio 2015 CTP(在Roslyn编译器下)执行相同的代码,则会为Debug和Release设置生成以下输出: …
以下是......
SomeType _someProperty;
public SomeType SomeProperty
{
get
{
if (_someProperty == null)
_someProperty = new SomeType();
return _someProperty;
}
}
Run Code Online (Sandbox Code Playgroud)
...具有与以下相同的功能?
SomeType _someProperty;
public SomeType SomeProperty
{
get { return _someProperty ?? (_someProperty = new SomeType()); }
}
Run Code Online (Sandbox Code Playgroud)
根据ReSharper他们的确如此.如果是这样,有人可以解释第二个块的语法吗?