Writing a simple C# script and evaluating it within the Visual Studio interactive window
In this section, we will walk you through the basics of C# scripting and show you how to use the Visual Studio interactive window to evaluate a C# script.
Getting started
You will need to have Visual Studio 2017 Community edition installed on your machine to execute this recipe. You can install a free community edition from https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=Community&rel=15
How to do it...
- Open Visual Studio and start the
C# Interactive
window by clicking onView |
Other Windows |
C# Interactive
:
- Type
Console.WriteLine("Hello, World!")
in the interactive window and hit the Enter key to evaluate the C# expression. - Verify that
Hello, World!
is output as a result in the interactive window:
- Now, type a variable declaration statement of type
List<int>
with a collection initializer:var myList = new List<int> { 3, 2, 7, 4, 9, 0 };
and press the Enter key. - Next, type...