0
public class Report
{
    public static int A = B + 2;
    public static int B = A + 2;
}

AFAIK, in a class it executes the fields in the order of their presence in the class. Referring the first time to Report class, the fields will be initialized as A = 2 and B = 4

But what is the order in partial classes?

public partial class Report
{
    public static int A = B + 2;
}

public partial class Report
{
    public static int B = A + 2;
}

Maybe if the classes are in the same file, it still executes in the order of presence in the file. Or what?

But/And what is the order if the partial classes are in different files?

By the way, I am asking this out of curiosity.

serdar
  • 1,564
  • 1
  • 20
  • 30
  • 1
    Because it is confusing. Moving a public declaration shouldn't change the code produced. It could at least product a warning – Rob Nov 07 '14 at 11:42
  • 1
    Well, according to me, the class, in this case, execute in FCFS order. The class written first is executed first in this case. – SanyTiger Nov 07 '14 at 11:43
  • 4
    If it's any consolation, I'm trying to get this *better* specified in the ECMA version of the C# 5 spec... – Jon Skeet Nov 07 '14 at 11:43

0 Answers0