Lea Cohen
Lea Cohen

Reputation: 8190

C# file size limit

I have a website built with ASP.NET (.NET 2.0). I have a lot of classes in my business logic, and I keep all of them in one file (BL.cs).

I now got to a stage where I have 11,000 lines of code in this file. Is this a problem - should I separate it into several files, each class in a different file? Is there a limit that the cs file shouldn't exceed?

Upvotes: 6

Views: 2403

Answers (5)

IanNorton
IanNorton

Reputation: 7282

This is very much a problem from a maintability point of view.

You will almost never need hand written code to be more than a few hundred lines per class and you should always aim to use one class per file ( and name files with the same name as your class ). This is general good form for managing a project, especially a large one.

If this is one huge auto-generated class you might consider splitting it into multiple files using the partial keyword in each.

Upvotes: 1

Gup3rSuR4c
Gup3rSuR4c

Reputation: 9490

I doubt there's a limit on the file size, I've seen EF files at 30k+ lines, however, you should be separating everything into individual files anyway for just plain usability and readability reasons.

Upvotes: 1

FIre Panda
FIre Panda

Reputation: 6637

You should keep each class in separate file for better readability and managability.

Upvotes: 2

Darin Dimitrov
Darin Dimitrov

Reputation: 1038820

I stick to the following rule: 1 file per class (unless for nested classes of course). 11,000 lines of code in a single file looks monstrous.

Upvotes: 8

Brian Rasmussen
Brian Rasmussen

Reputation: 116401

To be honest I don't know if there is a size limit, but 11.000 lines of code is a lot to handle in a single file.

You will find that VS runs a lot smoother if you split the code into multiple files and it will make it easier for you and your fellow developers to focus on a specific set of classes for any given task.

Programming is all about building complex systems from simple parts. Storing all your parts in a single, giant file goes against that idea.

Upvotes: 6

Related Questions