In this tutorial we will look at the Visual Studio Integrated Development Interface (IDE) and see how it makes our software development much easier. We will look at syntax highlighting, Intellisense and the toolbars. We will also look at different methods of running an application.
For this tutorial we will be using the free version of Microsoft Visual C# Express to demonstrate the features of the development interface, although there is not a great difference between Visual C# Express and the full Visual Studio.
Syntax Highlighting
You have probably noticed that as you type code in, Visual Studio will change the colour of the words. This is Syntax Highlighting and it the there purely to aid readability.
In general:
- keywords are blue
- comments are green
- strings are red/brown
- classes are gray
You can change these colours from within the program settings dialog box if you would prefer different colours.
IntelliSense
Using our hello world application from the last tutorial, we are going to invoke Intellisense and let it write code for us. If you types in the code in the last tutorial you will have seen Intellisense, however if you used copy and paste to insert the code, then now you will see Intellisense.
Start off my deleting the
Console.WriteLine line, then just type 'C'. Notice a popup window with a list of items beginning with 'C', also note that Console is the highlighted item. This is the item that Visual Studio thinks you are most likely to use in the current context. We can now press Enter, or just '.' and Intellisense will type the rest of the word for you, and bring up another selection box, this time with WriteLine selected.
You can use the arrow keys to select different items on the list. Scroll up to C and notice that Console is not on the list any more. This is because Intellisense will only offer suggestions based on the current context. For this little example it will show all the methods and properties of the Console.
As we are looking at 'C' on the list, type in 'W' and the Intellisense will jump back down to WriteLine. We can see by the icon (see below for examples) that WriteLine is a method we can call, so now type in an open parenthesis and Intellisense will now give you the method name, a description of what it does and the parameters that it takes. Notice in the top left it says "1 of 19″, this function has been overloaded and can take many different types of parameters. Don't worry about this just yet though, but you can use the up and down keys to look through them if you wish.
Console.WriteLine("Hello World!");?C.("Hello World!");If for some reason Intellisense does not automatically popup, you can use (Ctrl+Space) to have it popup at the cursor.
Intellisense Icons
Here are a few of the common icons used in Intellisense and what they mean. Don't worry if you don't understand the terms, they are all explained in later tutorials.
Regions and Blocks
Visual Studio and Visual C# allow sections of code to be hidden away, or collapsed. A section of code between two braces is called a region, and can be collapsed or expanded by using the plus or minus icon near the gutter. The gutter is the grey column down the left hand side of the code window. We will see what the gutter is used for when we look at Debugging.
You can collapse block level code that is nested within your methods, you can collapse the namespace, or you can collapse any block of code between the two.
The code does not get deleted, just hidden from view. This is very useful because it can hide away code that you may not be interested in and declutter the code window, so all your attention is on the code you are writing.
You can also define your own collapsible blocks of code by using the region and endregion keywords. To start a region, type #region , and at the end of the block of code type #endregion. The editor will now allow you to collapse this code.
Console.WriteLine("Please Enter Your Age:");
string myName = Console.ReadLine();
Console.WriteLine("You Entered: " + myName);
#endregion
Listing 1-1, Example usage of Region and Endregion
Summary and Conclusions
In this tutorial we saw how the Visual C# IDE is very clever at predicting what you are going to type, and it is able to improve your productivity by reducing the amount of time spent coding. We also saw how regions and blocks can be collapsed to declutter the code window.
In the next tutorial we will have a look at the task list and see how we can use it to help plan our development.
No comments:
Post a Comment