C# 4.0 Compiler Crash

后端 未结 4 2014
不知归路
不知归路 2021-02-04 23:52

This code sample is not able to be compiled. Any work arounds out there?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

n         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-05 00:20

    I reproduced the crash using VS2010 (WinXP 64).

    Two workarounds:

    1. don't use the using alias

    The following code compiles cleanly on VS2010:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Func True = (a, b) => a;
                Func False = (a, b) => b;
    
                Func, 
                     Func,
                     Func > And 
                    = (x, y) => x(y(True, False), False);
            }
        }
    }
    

    2. use the Mono compiler

    No problem with Mono 2.10 compiler (dmcs).

    [mono] /tmp @ dmcs test.cs
    test.cs(18,42): warning CS0219: The variable `And' is assigned but its value is never used
    Compilation succeeded - 1 warning(s)
    [mono] /tmp @ ./test.exe 
    [mono] /tmp @ 
    

    This was tested on linux.

    1. You can run binaries created with mono on Windows .NET.
    2. Mono compiler comes with an installer MSI and runs on Windows as well.

提交回复
热议问题