In C# how many lines before a class should be consider to be refactored?

When the class violates the SRP, it's time to refactor.

The single responsibility principle is a computer programming principle that states that every module or class should have responsibility over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class. All its services should be narrowly aligned with that responsibility


If your classes have broken one of following "rules", you should consider to refactor.

You are looking for SOLID, more detailed screencasts can be found here.

  • SRP: single responsibility principle, there should never be more than one reason for a class to change.

  • OCP: open closed principle, software entities (classes, modules, functions, etc.) should be open for extension but closed for modification.

  • LSP: liskov substitution principle, functions that use references to base classes must be able to use objects of derived classes without knowing it.

  • ISP: interface segregation principle, clients should not be forced to depend upon interfaces that they do not use.

  • DIP: dependency inversion principle:

    • high level modules should not depend upon low level modules. Both Should depend upon abstractions.

    • abstractions should not depend upon details. Details should depend upon abstractions.


Don't let LOC be your primary metric. 50 lines seems really small to me. With 50 line files, you will end up having an unfriendly number of class files in the solution. Your productivity will be dampened by all the navigation you will be doing between files and your IDE will always be littered with too many tabs. I personally try to organize classes into logical groups by namespace first. On a class by class basis, I try to make the code smaller and easier to read. Sometimes, class files do get large. I start to get a sick feeling when the class file is 2000+ lines. Anything less than that, I deal with on a case by case basis.