Splitting a code file into multiple files

Suppose you have one c# script, abc.cs, which is very long … 100s of lines. Is there a way to organize it somehow? Thanks!

If you are using C# you can split one class into separate files if that’s easier for you to work with.

In each file, put the word “partial” before the word “class”, and add descriptions to your file names after a period.

For example: “MyClass.cs”, “MyClass.Attack.cs”, “MyClass.Flee.cs”.

public partial class MyClass { }

Reference:

Note that “all parts” must have the partial keyword.

(So, you don’t just add it to the “others”, you put it on the “first” one and all the others as well.)

AHHG! Don’t copy and paste!

We’re dealing with object-oriented code here, this is the perfect case for using subclasses. You can put more that one class in a file, or have each in separate files. But all functions for a single class should go in the same file.