Search code examples
c#class.net-assembly

Order of Classes within an Assembly


What determines the order of classes within an Assembly?

And.. is there a way to change it?


Additional info: you can check the ordering either through reflection yourself, or you can use a tool like ILDASM, disable the alphabetical sorting, and then you will also get the order.

Order seems to be in a strange way determined by the compiler.

I already tried some things.. like renaming the classes (order stays the same), also editing the .csproj file to change the order of the .cs files.

My main focus is VS2008, C#, .net 3.5.


Update: I do have a scenario where the order matters (external program going through my assembly through reflection) - and I need special order there. Apart from this - you are totally right - order really should not matter.


Solution

  • I'm going to stick my neck out here and say this is an implementation detail and may well be decided by any particular compiler.

    Since this is an implementation detail you shouldn't or needn't be concerned. Of course if this really is important (can't see why) you can always write your own IL.

    I leave you with the following quote from Eric's blog:

    Is compiling the same C# program twice guaranteed to produce the same binary output?

    No.