对象类型末尾的&符号是什么?

我不得不重新编译一些代码,我不知道这个语法是什么? 你可以帮忙,还是指点一下这是什么意思? 我用谷歌搜索并搜索了这个网站,找不到任何东西。

只需一行代码:

Rectangle pageBounds; // ISSUE: explicit reference operation // ISSUE: variable of a reference type Rectangle& local = @pageBounds; 

Rectangle对象类型末尾的“&”符号是什么,pageBounds变量之前的“@”是什么?

这是我需要修复的最后一行代码,以便再次编译这个可执行文件。

这是使用此语法的方法,我可以删除它吗?

 protected override void OnPrintPage(PrintPageEventArgs e) { Application.DoEvents(); ++this._pageNum; float num1; if (this.Header != null) { num1 = this.Header.CalculateHeight(this, e.Graphics); this.Header.Draw(this, (float) e.MarginBounds.Top, e.Graphics, e.MarginBounds); } else num1 = 0.0f; float num2; if (this.Footer != null) { num2 = this.Footer.CalculateHeight(this, e.Graphics); this.Footer.Draw(this, (float) e.MarginBounds.Bottom - num2, e.Graphics, e.MarginBounds); } else num2 = 0.0f; Rectangle pageBounds; // ISSUE: explicit reference operation // ISSUE: variable of a reference type Rectangle& local = @pageBounds; int left = e.MarginBounds.Left; Rectangle marginBounds = e.MarginBounds; int y = (int) ((double) marginBounds.Top + (double) num1); marginBounds = e.MarginBounds; int width = marginBounds.Width; marginBounds = e.MarginBounds; int height = (int) ((double) marginBounds.Height - (double) num2 - (double) num1); // ISSUE: explicit reference operation local = new Rectangle(left, y, width, height); float yPos = (float) pageBounds.Top; bool flag = false; int num3 = 0; while (this._printIndex  (double) pageBounds.Bottom && num3 != 0) { flag = true; break; } else { printElement.Draw(this, yPos, e.Graphics, pageBounds); yPos += num4; ++this._printIndex; ++num3; } } e.HasMorePages = flag; } 

在该行代码之前的注释正在告诉您究竟发生了什么。 类型名称后面的&符号表示它是引用类型,变量名称前面的@生成对该变量的引用。

(@符号也可以在C#代码中用于“转义”关键字以用作变量名,但这不是这里发生的事情。“pageBounds”不是C#关键字。)

请注意,这不是有效的C#语法 – 您无法在C#中引用本地变量。 例如,当您使用refout参数时会隐式发生这种情况,但会使用关键字而不是显式键入参数作为参考。 (例如,如果你有一个out int x ,那么该变量的类型是Int32& 。)代码的意图 ,如果它是合法的C#,那就是pageBoundslocal是具有两个不同名称的同一个实例 ; 你做的任何事都发生在另一个。 所以,例如,这个非法代码:

 Rectangle pageBounds; Rectangle& local = @pageBounds; local = new Rectangle(); 

与此法律代码相同:

 Rectangle pageBounds = new Rectangle(); 

如果你试图编译as-decompiled的代码,你会得到一个错误,因为编译器将&视为按位,并且会抱怨你使用了一个类型,好像它是一个变量。 但这没关系,因为你没有从C#源文件中获取它。 你反编译了一个IL方法来获取它,你可以在IL中做很多在C#中非法的事情。 当您反编译代码时,这种情况一直发生; 你会看到非法的类和方法名称。 它只是意味着编译器根据原始代码生成IL,而不是直接转换回C#,而是按照您想要的方式运行。 你得到的代码很简单,反编译器最好尝试从它生成的IL生成C#代码。

您可以在众多关于它们的Jetbrains错误报告中看到产生这些引用的代码类型的示例:

看到这里 – http://msdn.microsoft.com/en-us/library/aa664670 (v=vs.71) .aspx (从未使用过)

The prefix "@" enables the use of keywords as identifiers ,这在与其他编程语言交互时很有用。 字符@实际上不是标识符的一部分,因此标识符可能在其他语言中看作普通标识符,没有前缀。 带有@前缀的标识符称为逐字标识符。 允许使用@前缀作为非关键字的标识符, but strongly discouraged as a matter of style

这个例子:

 class @class { public static void @static(bool @bool) { if (@bool) System.Console.WriteLine("true"); else System.Console.WriteLine("false"); } } class Class1 { static void M() { cl\u0061ss.st\u0061tic(true); } }