Community discussion forum

Defining a function in a separate file

  • 3 months ago

    I'm really a beginner at C#, so I might not even be calling this the right thing, but here goes. I'm writing a small program with only a few user defined functions. Is there any way to define those functions in a separate file (like a DLL, or simply another .CS file) so that I can call them from within the main program? I'm using Visual Studio 2008 Pro, and I'm just looking to do this so I don't have all my user-defined functions cluttering up the code behind my GUI. Plus, I would like to be able to add that file to another project, and be able to use those functions right away in the next project. Thanks in advance for any help!

  • Advertisement

    Simply the fastest line-level profiler for .NET ever

    “The low overhead means it has minimal impact on the execution of my program”
    Mark Everest, Development Team Leader, Renault F1 Team Ltd.

    Try out the new ANTS Profiler 4 for yourself. Download your 14-day trial now

  • 3 months ago

    Take a look at this article for creating a 'class library'. Although it's for an older version of .Net, the theory is still the same. 

    http://www.dotnetheaven.com/Uploadfile/mahesh/pr1202172006014101AM/pr12.aspx

    Once you've created your class library, you can create a new project for your GUI and add a reference to the DLL that you've created above.

     

     

  • 3 months ago

    Awesome! That really helps me out. That's pretty much exactly what I'm looking for. Thanks again!

  • 3 months ago

    I'm glad that helps - good luck with that!

Post a reply

Enter your message below

Sign in or Join us (it's free).