Originally Title : "Mono 2.7: Array Initializer Bug"
I'm having an issue with mono where array initialization (at least for multidimensional arrays) does not work when inlined in a method call. It looks like the mono compiler is emitting the assignments after the method call.
For instance:
MathLib.PrintMatrix(new double[,] { {1.0, 1.0}, {1.0, 1.0} });
// Prints the following
// 0.0, 0.0
// 0.0, 0.0
However, the following code works correctly:
var myArray = new double[,] = { {1.0, 1.0}, {1.0, 1.0} };
MathLib.PrintMatrix(myArray);
// Prints the following
// 1.0, 1.0
// 1.0, 1.0
I couldn't find any release note addressing this issue, and I'm currently running an older version (which I don't want to update unless it's going to 开发者_StackOverflow中文版be benificial). Does anyone know if this bug has been fixed?
I don't have 2.7 (a beta for 2.8) around but I have something older (2.6.7 in Ubuntu)
poupou@mizar:~/src$ gmcs --version
Mono C# compiler version 2.6.7.0
poupou@mizar:~/src$ cat x.cs
using System;
class Program {
static void PrintMatrix (double[,] values)
{
Console.WriteLine ("{0}, {1}\n{2}, {3}", values [0,0], values [0,1], values [1,0], values [1,1]);
}
static void Main ()
{
PrintMatrix (new double[,] { {1.0, 2.0}, {3.0, 4.0} });
}
}
poupou@mizar:~/src$ gmcs x.cs
poupou@mizar:~/src$ mono x.exe
1, 2
3, 4
and something a lot newer: 2.11 from git
[mono] ~/src @ mcs --version
Mono C# compiler version 2.11.0.0
[mono] ~/src @ mcs x.cs
[mono] ~/src @ mono x.exe
1, 2
3, 4
So I believe your issue is related to using an old, unsupported beta release of Mono.
精彩评论