Using an external file for funtions

  • Thread starter Thread starter Rob Stevens
  • Start date Start date
R

Rob Stevens

Is there anything in c# like using an external file or an include
file to store some of your functions? It's getting really hard to
find your way around when you have so many functions in your
main file.

Thanks
 
There are no header or include statements as in C/C++. You can and should
separate your classes into separate files. It sounds like you are asking
something different though.
 
Rob,

No, there isn't. You should create a separate assembly and expose the
functions as members on types and then access those in other assemblies
where you want to use the functionality.
 
Hi,

Create a library project in your solution, you will end with a .dll that you
can use in as many projects as you want.
 
Rob said:
Is there anything in c# like using an external file or an include
file to store some of your functions? It's getting really hard to
find your way around when you have so many functions in your
main file.

There are many Visual Studio features designed to help you navigate your code.

For instance, in your code window, you have quick access to members of your
class via a dropdown. There's also the Class View which allows you to see
classes in your current solution broken down by project, namespace, class, and
then view the methods and properties in those classes, etc...


Chris.
 
Adding to Chris Shepherd's comment,
I tend to use a lot of the regions in my code for organization:
eg:

#region My Private Functions

private void MyfirstPrivateFctn()
{
}

#endregion

It realy helps clean up the code and make it managable.
Class diagrams also go a LONG way to readable code.

Hope this helps, good luck.
 
Another option (may good already mentioned) is that if you find a
single class file is *still* overweight despite #regions etc, you can
use (in 2.0 and above) partial classes to split the single class into
multiple files (grouping related functionality). I find this
especially useful if I am implementing non-trivial interfaces etc - I
can have a MyClass.cs and a MyClass.ITrickyInterface.cs file, with all
the ITrickyInterface junk in the second file.

Marc
 
Thanks averyone for the responses, I definitely know what I need
to do now.

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top