10

Is there any overhead using partial classes in case of memory, performance etc?

If we create a partial class can we identify whether the class was partial or not using reflector??

rahul
  • 184,426
  • 49
  • 232
  • 263

3 Answers3

17

No. They are compiled to the same IL as if they weren't partial. It's a purely compile-time thing - the CLR doesn't even know that they were ever partial.

Note that with partial methods introduced into C# 3, the method doesn't even get emitted in the IL unless it's implemented in one of the files. Both the calls and the declaration get stripped out by the compiler.

It's possible that it'll slow down the compiler an imperceptible fraction of a millisecond, of course :)

Trisped
  • 5,705
  • 2
  • 45
  • 58
Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • If we create a partial class can we identify whether the class was partial or not using reflector?? – rahul Jun 26 '09 at 11:41
  • 2
    Partial is much like whitespace, only with an EOF involved. The compiler parses it, but after that there's no trace it ever existed. – Matthew Scharley Jun 26 '09 at 11:45
  • 1
    @Phoenix: No. The only time you could find that out would be if you had debug symbols to analyze, and found that some of the code came from one file and some from another. – Jon Skeet Jun 26 '09 at 11:46
3

No, all class files will get consolidated at compile time.

Here's the msdn article on partial types.

Each source file contains a section of the type or method definition, and all parts are combined when the application is compiled.

Joseph
  • 25,330
  • 8
  • 76
  • 125
2

No. They are compiled into one class. It is purely a language feature.

Simon P Stevens
  • 27,303
  • 5
  • 81
  • 107