小编del*_*eyk的帖子

CSC和Roslyn编译器的静态lambda表达式评估的区别?

请考虑以下示例代码.

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编译器下)执行相同的代码,则会为DebugRelease设置生成以下输出: …

c# csc roslyn

6
推荐指数
1
解决办法
1260
查看次数

ReSharper想要"优化"我的代码

以下是......

    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他们的确如此.如果是这样,有人可以解释第二个块的语法吗?

.net c# resharper

3
推荐指数
1
解决办法
147
查看次数

标签 统计

c# ×2

.net ×1

csc ×1

resharper ×1

roslyn ×1