C# Script files is similar like other script files that contain a piece of C# code and can execute and returns the results. As I said it is only piece of code – you really don’t have to have like a class or method to get the result. The C# script file (CSX) file is it’s own container and execute like a method. For Visual Studio, you can execute the CSX Script either using C# Interactive Window or CSI Command Line Window.
Before your proceed further, you must read following two posts to understand more about the new C# Interactive Window and the Command Line Interactive script engine for Visual Studio.
- Use C# Interactive Window for your coding experiment in Visual Studio 2015
- Command Line C# Interactive Script Execution for Visual Studio
Consider you have following C# Script file named “MyScript.csx” which just print a series of number from a defined collection.
To run the script from the C# Interactive Window, write the following command and press enter.
You will have following output :;
Similarly from the Command Prompt, open the Visual Studio Command Prompt and run the following command.
Once the script loads and execute, you will have the following output.
Hope this helps !