From the course: Visual Studio 2019 Essential Training

Use IntelliSense effectively - Visual Studio Tutorial

From the course: Visual Studio 2019 Essential Training

Start my 1-month free trial

Use IntelliSense effectively

- [Instructor] IntelliSense is one of the most helpful features I can think of within Visual Studio. When you are writing code, it gives you instant automatic context aware help. Let's go look at what's considered IntelliSense. I have set the focus inside this file, then I'll go to the Edit menu, and choose this IntelliSense sub menu. This is a list of the IntelliSense features. Really they are separate services that fall into the IntelliSense category. I'll look at List Members, Parameter Info, Complete Word in this video. Later I'll look at other services, like Insert Snippet. So we'll start by looking at the auto-complete. This is what you see every time you start typing inside the editor. So as I start typing letters like d-e, I see a list of potential items that make sense for me to use in my code, like decimal or decoder. Let's try a different set of letters. Double, type in d-o-u, now I can see there's two doubles. This is the .net type, this is the C# keyword. I've mentioned this before, but there's a filter available here, so I can filter down to only look at keywords, or only look at types. So that's really useful when you're working with a lot of different reference assemblies in your project. I want this Double item, so I'll choose it with my mouse, or hit the tab key, and Visual Studio will stub in that code. And here's what I want you to see. Erase this. Now the List Members list box is not showing anymore. I can always activate that with this keystroke Ctrl-J, without having to type anything. And you'll notice that it remembered the last item I selected on the list. Next we want to look at auto-completion, where I can have Visual Studio complete my typing for me. For this demonstration, I'll be using this class here, the StreamableBookInformation class. It's really just an empty class and it has a long name, and has some interesting capitalized letters. S, B, and I. And you'll see why that's important in a minute. As I type the first couple of letters of Stream, I see that I filtered down to two potential choices, SteamableBookInformation and another one, a StringNormalizationExtension. Obviously the one on the top is the one we want to use. What we're looking at here is how to have Visual Studio finish typing this word. So I can use the mouse by double clicking here. Or I can use the tab, like this. Now notice where the cursor is. The cursor is right at the end of the class name. Try it again, this time I'll do, this time I'll use the spacebar. Now what's the difference between these two? The difference is where the cursor is. I typed the space, so what Visual Studio did is auto-complete the word, and then honor what I typed in on the keyboard, which is the space. Yeah, see I need a new equal sign here, so I'm going to put that in there instead. And this is also the same with the parenthesis. Show you that one. Now I'll type in the open paren, and you'll see Visual Studio finished typing the class name, and then put my two double parenthesis in. I find that extremely handy. I don't have to type the entire class name. Next we'll look at fixing issues with code. And you could use this key stroke, Ctrl-Spacebar, also known as CompleteWord. So this can work like this. I'll erase a couple letters on this property on the book class, and now I can do a Ctrl-Space to have it auto-complete, or complete that word. Let's try it here with Price. Erase a few letters, Ctrl Spacebar. Tell you where I use this feature a lot, let's go back and look at this class. Let's say that I made a typo, and instead of using a capital letter B here, I used a lowercase letter b. Now I'm getting a red squiggle signifying that there is no type called StreamableBookInformation. Now you and I know it's there, but right now I'm in C# which is a case sensitive language and this is not a valid class name. Here's my favorite use of this feature. Put your cursor anywhere inside this misspelled class name, then use Ctrl-Spacebar. And instantly Visual Studio looks at that, and realizes that there is a match for that, it found a unique match for this word, but just spelled differently, so it auto-completes it for me. One more interesting thing. Remember I said it has three interesting letters, S, B, and I? So let's go back here and take a look at how that works, new s-b-i, tab. This works for any type. If you know the capitalized letter in the class name, you can use this technique. Finally, let's look at parameter information. Anytime you make a method call, and you want to know about the parameters, as you're typing the code, you'll get a parameter list, but you can always reinvoke it by using Ctrl-Shift-Spacebar, so let's look at what we can find out about WriteLines. So I'll put my cursor anywhere inside this set of parenthesis, hold down the Ctrl-Shift key, tap Spacebar, and it brings up the floating window, that tells me there are 18 overloads of the Console.WriteLine, and I can read about each of the overloads, and of course I can then use these up and down arrows on the tip, or on my keyboard, to read more information. I can't say enough good things about the IntelliSense support in Visual Studio. I simply could not live without this feature.

Contents