About Visual Studio C#

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Team Explorer

(bottom right) lets you track work items and share code with others using version control technologies such as Git and Team Foundation Version Control (TFVC)

Editor Window

(center), where you'll likely spend a majority of your time, displays file contents and is where you can edit code or design a user interface such as a window with buttons and text boxes

Solution Explorer

(top right) lets you view, navigate, and manage your code files and can help organize your code by grouping the files into solutions and projects

What are some steps you can follow to debug code?

1. Find the line of code that says Console.WriteLine($"\nHello {username}!");. To set a breakpoint on this line of code, that is, to make the program pause execution at this line, click in the far left margin of the editor. You can also click anywhere on the line of code and then press F9. A red circle appears in the far left margin, and the code is highlighted in red. 2. Start debugging by selecting Debug > Start Debugging or by pressing F5. 3. When the console window appears and asks for your name, type it in and press Enter. The focus returns to the Visual Studio code editor and the line of code with the breakpoint is highlighted in yellow. This signifies that it's the next line of code that the program will execute. 4. Hover your mouse over the username variable to see its value. Alternatively, you can right-click on username and select Add Watch to add the variable to the Watch window, where you can also see its value. 5. To let the program run to completion, press F5 again.

How to configure Visual Studio to use environment settings tailored to C# developers

1. On the menu bar, choose Tools > Import and Export Settings. 2. In the Import and Export Settings Wizard, select Reset all settings on the first page, and then choose Next. 3. On the Save Current Settings page, select an option to save your current settings or not, and then choose Next. (If you haven't customized any settings, select No, just reset settings, overwriting my current settings.) 4. On the Choose a Default Collection of Settings page, choose Visual C#, and then choose Finish. 5. On the Reset Complete page, choose Close.

How to change Visual Studio to the dark theme

1. On the menu bar, choose Tools > Options to open the Options dialog. 2. On the Environment > General options page, change the Color theme selection to Dark, and then choose OK. The color theme for the entire IDE changes

Steps for Creating a Program in Visual Studio

1. Open Visual Studio 2. Choose Create a New Project. The Create a New Project window opens and shows several project templates. 3. To find the template you want, type or enter .net core console in the search box. The list of available templates is automatically filtered based on the keywords you entered. You can further filter the template results by choosing C# from the Language drop-down list. Select the Console App (.NET Core) template, and then choose Next. 4. In the Configure your new project window, enter HelloWorld in the Project name box, optionally change the directory location for your project files, and then choose Create. 5. Now, start the app. You can do this by choosing Start Without Debugging from the Debug menu on the menu bar. You can also press Ctrl+F5. Visual Studio builds the app, and a console window opens with the message Hello World!. You now have a running app! 6. To close the console window, press any key on your keyboard. 7. Let's add some additional code to the app. Add the following C# code before the line that says Console.WriteLine("Hello World!");: This code displays What is your name? in the console window, and then waits until the user enters some text followed by the Enter key. 8. Change the line that says Console.WriteLine("Hello World!"); to the following code: Console.WriteLine($"\nHello {name}!"); 9. Run the app again by selecting Debug > Start Without Debugging or by pressing Ctrl+F5. Visual Studio rebuilds the app, and a console window opens and prompts you for your name. 10. Enter your name in the console window and press Enter. 11. Press any key to close the console window and stop the running program.

How refactoring and Intellisense can help you code more efficiently

1. rename the name variable: 2. Double-click the name variable to select it. 3. Type in the new name for the variable, username. Notice that a gray box appears around the variable, and a light bulb appears in the margin. 4. Select the light bulb icon to show the available Quick Actions. Select Rename 'name' to 'username'. The variable is renamed across the project, which in our case is only two places. 5. Now let's take a look at IntelliSense. Below the line that says Console.WriteLine($"\nHello {username}!");, type DateTime now = DateTime.. A box displays the members of the DateTime class. In addition, the description of the currently selected member displays in a separate box. 6. Select the member named Now, which is a property of the class, by double-clicking on it or pressing Tab. Complete the line of code by adding a semi-colon to the end. 7. Below that, type in or paste the following lines of code: int dayOfYear = now.DayOfYear; Console.Write("Day of year: "); Console.WriteLine(dayOfYear); 8. Next, we'll use refactoring again to make the code a little more concise. Click on the variable now in the line DateTime now = DateTime.Now;. Notice that a little screwdriver icon appears in the margin on that line. 9. Click the screwdriver icon to see what suggestions Visual Studio has available. In this case, it's showing the Inline temporary variable refactoring to remove a line of code without changing the overall behavior of the code 10. Click Inline temporary variable to refactor the code. 11. Run the program again by pressing Ctrl+F5. The output looks something like this:

What are some of the most popular features in Visual Studio?

Squiggles Quick Actions Code Cleanup Refactoring Intellisense Search Box Live Share Call Hierarchy CodeLens Go To Definition Peek Definition

Under what platforms is Visual Studio available?

Windows and Mac

Code Cleanup

With the click of a button, format your code and apply any code fixes suggested by your code style settings, .editorconfig conventions, and Roslyn analyzers and helps you resolve issues in your code before it goes to code review

Quick Actions

a light bulb that may appear in the left margin with actions to fix the error

Intellisense

a term for a set of features that displays information about your code directly in the editor and, in some cases, write small bits of code for you and It's like having basic documentation inline in the editor, which saves you from having to look up type information elsewhere

Live Share

allows you to collaboratively edit and debug with others in real time, regardless of what your app type or programming language, instantly and securely share your project and, as needed, debugging sessions, terminal instances, localhost web apps, voice calls, and more

What is the process of testing code for bugs called?

debugging

CodeLens

helps you find references to your code, changes to your code, linked bugs, work items, code reviews, and unit tests, all without leaving the editor

Refactoring

includes operations such as intelligent renaming of variables, extracting one or more lines of code into a new method, changing the order of method parameters, and more

Search Box

is a great way to rapidly find what you need in Visual Studio when you start typing the name of something you're looking for

What is the difference between Console.Write and Console.WriteLine?

it doesn't add a line terminator after it prints

What about Visual Studio can be personalized?

it's user interface

What do the Intellisense features vary by?

language

When you write code, you need to

run it and test it for bugs

Go To Definition

takes you directly to the location where a function or type is defined

What does a template in Visual Studio contain?

the basic files and settings needed for a given project type

Call Hierarchy

this window shows the methods that call a selected method and can be useful information when you're thinking about changing or removing the method, or when you're trying to track down a bug

Squiggles

wavy underlines that alert you to errors or potential problems in your code as you type and enable you to fix problems immediately without waiting for the error to be discovered during build or when you run the program and you see additional information about the error

Peek Definition

window shows the definition of a method or type without actually opening a separate file

Is Code Cleanup available for C# only?

yes

How can Visual Studio's debugging system be used to debug code?

you step through code one statement at a time and inspect variables as you go. You can set breakpoints that stop execution of the code at a particular line. You can observe how the value of a variable changes as the code runs, and more


Kaugnay na mga set ng pag-aaral

Chapter 28 Obstructive Pulmonary Diseases

View Set

FT III-FT IV TCP/IP STRUCTURE AND ADDRESSING (190E10-3) (lesson one practice questions)

View Set

Ch. 5 - Network and Transport Layers

View Set

Dysrhythmias and Conduction Problems

View Set