Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

Angus Eliott
Angus Eliott
3,793 Points

Run a .cs?

I have this snippet of code that I want to run multiple times throughout the execution. I put it in another code file to be run whenever I need it. My question is, how do you run another code file that is in the same solution? and how do I transfer data to and from it?

1 Answer

Steven Parker
Steven Parker
231,261 Points

There's a mechanism called Process.Start that can cause another executable to run, and you can pass data using streams, a data file, or with command-line arguments. There's a good bit of overhead involved, usually only worthwhile when you're calling a program that you don't have source code for.

But if you have the code, it might be much easier to just include the snippet in the build of each other program that uses it, and just call it as needed. Wouldn't that do the job?