Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
strauss_d_getting_started_with_visual_studio_2022_learning_a.pdf
Скачиваний:
123
Добавлен:
26.06.2023
Размер:
17.04 Mб
Скачать

Chapter 2 Working with Visual Studio 2022

When we look at the table data after the UPDATE statement (Figure 2-74), you will see that the table has been updated to display the correct priceCategory values for the items in the table.

Figure 2-74.  Table updated

While running SQL statements isn’t mind-blowing, it is very convenient to be able to do all this without ever leaving Visual Studio. The Server Explorer offers much more functionality than illustrated in this chapter. Dig around it a bit more and see what the Server Explorer can do for your productivity.

Visual Studio Windows

I have often maintained that developers get stuck in a rut when working with Visual Studio. They tend to stick to what they know and keep doing things that way until the cows come home.

This isn’t necessarily a bad thing, but developers might miss out on some of the excellent tools and features that Visual Studio provides. In this section, I want to briefly discuss two items found under the View Other Windows menu, as seen in Figure 2-75.

150

Chapter 2 Working with Visual Studio 2022

Figure 2-75.  Other Windows in Visual Studio

There are too many windows to discuss in this chapter, but I will touch on two that I find very useful.

C# Interactive

How often have you wanted to test a tiny bit of code to see if it works correctly? Well, with C# Interactive, you can do just that without having to debug your entire solution. Found toward the bottom of the View Other Windows menu, C# Interactive is almost hidden. But gems usually are, and you’ll love using it if you don’t already.

Click C# Interactive and paste the following code in Listing 2-30. After pasting the code into C# Interactive, hit the Enter key to run the code.

151

Chapter 2 Working with Visual Studio 2022

Listing 2-30.  Running a LINQ Query

var numList = new List<int>() { 153, 114, 116, 213, 619, 18, 176, 317, 212, 510 };

var numResults = numList.Where(x => x > 315); foreach(var num in numResults)

{

Console.WriteLine(num);

}

The results are displayed below the code you pasted. Your C# Interactive window should now appear as illustrated in Figure 2-76.

Figure 2-76.  C# Interactive code results

C# Interactive is what we refer to as a REPL (Read-Eval-Print Loop). Being able to input expressions that are evaluated and having the results returned makes on-the-spot debugging possible in Visual Studio.

C# Interactive supports IntelliSense, so you get the same kind of editor experience as in Visual Studio. For a list of available keyboard shortcuts, REPL commands, and Script directives that C# Interactive supports, just type in #help and press the Enter key.

152