How to do it...

  1. Start the Visual Studio 2017 develop command prompt and execute the command csi.exe to start the C# interactive session.
  2. Type Console.WriteLine("Hello, World!") on the console and click on the Enter key to execute the command in interactive mode:
  1. Press Ctrl + C to exit the interactive mode.
  2. Create a script file MyScript.csx with the following code to output the arguments to the script:
var t = System.Environment.GetCommandLineArgs();

foreach (var i in t)
{
System.Console.WriteLine(i);
}
  1. Execute the script with arguments 1 2 3 and verify the following output. Also, note that after executing the script, we return back to the command prompt, not the interactive session:
c:>csi MyScript.csx 1 2 3
csi
MyScript.csx
1
2
3
  1. Now, execute the same script with an additional -i argument prepended and verify the same output as earlier, this time however, we return to an interactive prompt:
c:>csi -i MyScript.csx 1 2 3
csi
-i
MyScript.csx
1
2
3
>
  1. Execute Console.WriteLine(t.Length) and verify that the output is 6, confirming that the variable t declared in the script and initialized with the command-line arguments is still alive in the current interactive session.
  2. Press Ctrl + C to exit the interactive mode.
  1. Execute csi -i to start csi.exe in interactive mode and execute the #help command to get the list of available keyboard shortcuts, REPL commands, and script directives:
  1. Note that the set of available keyboard shortcuts, REPL commands, and script directives in csi.exe is a subset of the corresponding sets in the Visual Studio interactive window. Refer to the earlier recipes Using script directives and REPL commands in the C# interactive window and Using keyboard shortcuts for evaluating and navigating through script sessions in the C# interactive window, in this chapter for available shortcuts, commands, and directives in the Visual Studio interactive window.
  2. Press Ctrl + C to exit the interactive mode.
  3. Attempt to execute csi.exe with arguments, but no script name, and verify error CS2001 about missing source file:
c:>csi.exe 1
error CS2001: Source file 'c:1' could not be found.

You can read more about the command-line REPL and the arguments to csi.exe at https://github.com/dotnet/roslyn/wiki/Interactive-Window#repl.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset