问题描述
这问题是由乔恩飞碟双向的回答启发#431105> http://stackoverflow.com/questions/431091/is-there-ac-equivalent-to-cs-access-modifier-regions#431105
This question is inspired by Jon Skeet's answer:http://stackoverflow.com/questions/431091/is-there-a-c-equivalent-to-cs-access-modifier-regions#431105
他使得评论,这是可能的字段的一个文件中的次序无关紧要。我猜测这与该字段被初始化的顺序做的,但我认为这是一个危险的事情足以在此基础上的副作用,它保证了自己的问题,并讨论代码。
He makes a comment that it is possible for the order of fields in a file to matter. I am guessing that this has to do with the order that the fields are initialized, but I think it's a dangerous enough thing to code based on this side effect that it warranted its own question and discussion.
是否有周围其他的想法如何你的代码文件中的字段的顺序可以被操纵,并可能产生怎样的影响呢?
Are there other thoughts around how the order of fields within your code file could be manipulated and what impact that might have?
推荐答案
下面是从C#语言规范中的一个经典的例子(第10.5.5)
Here is a classic example from the C# language spec (Section 10.5.5)
class Test
{
static int a = b + 1;
static int b = a + 1;
static void Main() {
Console.WriteLine("a = {0}, b = {1}", a, b);
}
}
这是一个完全有效的程序和书面(一= 1,b = 2)。但是,如果你交换他们也将交换值的字段的顺序。
This is a completely valid program and as written (a = 1, b =2). However if you swap the ordering of the fields they will also swap values.
这篇关于请问在C#中物质场的顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!