Top 10 Hidden Gems in Visual Studio - Speed Up Development Without Increasing Your Costs

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Visual Studio is much more than just a text editor there's a ton of power built into the platform before you go out and spend money on third-party tools you should get to know what's already available to you in Visual Studio that is why in this video I'm going to show you ten of my favorite features to make your development faster and easier now if you're new this channel my name is Tim quarry and it's my goal to make learning c-sharp easier this channel is full of videos explain of various parts of c-sharp I also have a website where I provide full courses on c-sharp and sequel you can check it out at I am Tim quarry calm that's also the place where I have a blog post for this video it includes source code for my sample application both of the start of the video as well as at the end now if it's started in this example project now the the products a bit different this time we are not actually building anything instead I'm showing off Visual Studio so it's a little bit of a mess in some ways and that's okay so we have here is a class library called demo library and inside here I have six classes and an interface now just so you're aware this code doesn't really do anything so don't expect to download this and use it necessarily there aren't some code bits in here that actually would work but not as a cohesive whole so let's open up business logic and the business logic is just a little bit of code here just to get us started okay now the first tip is about opening up your project or your file in File Explorer or Windows Explorer now you may be used to doing this where you're right-clicking the project and say open folder and file explorer or maybe you right-click on the solution and do the same thing and you would do that like so open folder and file explorer and there you go but did you know that you can now right click on a tab and say open containing folder and that will take you right to the location of that file that way if it's Barry multiple levels deep inside folders inside your project you can go right there also if you right-click and say copy full path now you have the full path to where your look where that's located okay so if you wanted just a file path there it is okay so that's tip number one is to quickly get to your files on disk either to the right click show it open folder and file explorer or by right-clicking the tab and saying open full open containing folder or then copy full path as well that's kind of bonus this next tip was actually brought to me by one of the people on this channel people have follow me this is chase pane so if you see chase say idle and thank you this is so when we create an interface so if I say extract interface and we'll get to how to do this a minute but if I say extract interface one of the things that was having problems for me was it was creating full properties but now if I extract an interface notice its auto properties okay and the reason why is if I do it tools options then you go a text editor C sharp and they come down to advanced and in here if you make sure you scroll to the bottom you'll see this when generating properties prefer auto properties okay so what that does is it creates these auto properties instead of the full property okay so the other thing in that options menu you go back to the text editor C sharp advanced there's a couple of other things in here that are interesting okay so I want to point those out as well under the using directors new top there's these two checkbox here now I've already checked them but it says suggest using z' for types in reference assemblies and suggests using four types in new get packages so what is this this mean really what's saying I'm going to show you how to do it but essentially when you create something and let's actually just demo that's because it's a little bit easier to see if we come over here and I were to say let's just say I lager now I don't have an ilogger right now and so it's going to yell at me and do that red squiggly but if I ever hit ctrl dots or this little light bulb here if I drop it down either way I get the generate type I lager or it says using Microsoft I build that framework from Microsoft build that framework what that's going to do is bring a dll into my application it's going to reference it and that's gonna add a using statement to that dll because an ilogger instance is in that dll or it's going to go out and grab a nougat package called Microsoft I extensions don't logging down abstractions it's going to install that nougat package and then it will add a using statement for me to that nougat package DLL or it's going to install castlecore nougat package and again reference it and a user statement to it okay so what this does is it not only normally if I were I do i lager and didn't have those things checked what would do is say okay create an interface for you that's kind of blank or I can maybe create a method called you know just gonna try and figure out what's gonna do but it's all kind of inside your project at the very best what it might do is find out hey there's another project in the solution that has this do you want to add the reference to that project and add the using statement but now those two checkboxes checked what it does is it goes and looks at references now notice in the Assemblies there's a whole lot of references a lot that do not have a check mark next to them that means they're not brought into our application which is good we don't need a hundred or 200 dll's in our application however maybe we want something in one of those in which case we could either find it check the box come back out of user statement and then start using it or if we know that what we're typing is in that list but heat control dot and just say add it the same is true for nougat if the nougat package if we go search for one these nougat packages and it has something that's kind of common to that nougat package then there's a good chance that when we hit control dot it'll allow us right here to add that nougat package it's saved us a number of steps however this does not work for everything okay so as some things that just won't find it's not perfect but what it does do is it allows us in a lot of circumstances to move a little it fast or a lot faster to add things to our project bringing references in and then start using them right away okay so those two little check boxes make this a whole lot more powerful all right so those three settings in that let's go back over here to options so we have these two right here suggest using four types and that's those references I showed you there suggest using four types in NuGet packages that's the nougat package obviously and then also down here prefer Auto properties when generating properties okay so those three options there I recommend changing to what I have here these are not on by default all right let's get rid of that code okay one that you probably know about is the f12 so if I were to select this first name which is in the class person model if I would hit f12 it goes to the person model and right to the first name you probably know what that if you don't hey there's a bonus tip however what if I'm on data access dot load data and I hit f12 it goes to an interface well that doesn't really help me a lot because that's now I'm looking for I'm not looking for the interface I'm looking for the actual code there is a fix for this so if I hit ctrl f12 it takes me to the implementation and so what does is it goes and says where did you wire up to and it says okay I did access data access equals Oh new data access okay and so it finds it there and so ctrl f12 takes you to the implementation of that now this doesn't always work if you use depends a injection but it doesn't always get through to figure out which one you wired it up to so just know there are some limitations to it but control f12 if possible will take you to the implementation of the method or property if you select it even if it's against an interface so this is data access is actually an interface not an not a hard-and-fast class but visual studio is smart enough to go yeah I know it's an interface but you put a class in there let's go to that classes method called load data okay now if you are dealing with things that aren't a high-end interface so for example this first name it's just a person model okay it's not behind interface like this one is I could hit f12 or I could hold the control key and then click on it notice how it changes to a blue underlined line mouse over it okay in fact most things do I can click on it and go right to the definition so this takes me right to my person model now also if you were to have a very it would take you to that so for example person takes me up to the top where person is declare okay so control and then click or hit f12 after you've selected the item alright number four let's go to our helper class now our helper class this one right here I I just brought some code in okay so I just grabbed code bits in the internet and brought them in don't use these without testing them first these are just kind of code blocks I brought in just to give me some some depth to my module okay so for this first one I got it from Stack Overflow and actually generates lorem ipsum text the next the next section I got from this blog post and they do different things okay it's a real-time and so on and so forth so I have a hundred and eighty-three or so lines of code in here and that's me the want to show off a couple of things here so this one I think you're going to love okay this is what my favorite things if you hit ctrl T or if you want to use one hand you can hit ctrl comma either one ctrl T and that brings up this box over here in the right-hand corner now the cool thing that has little icons here that will help you or you can hit question mark so let's hit question mark first and notice it says okay symbol lines show this list files members and types and it has in front of it a one character identifier so what this one character data fire does is it filters down what this is gonna look for this is like a search but it's a different kind of search it's not gonna search your code it's going to search for specific things in your code methods classes files those type of things okay so let's start with a line number this is why you used rarely okay so just be aware of that but I want to show you just in case it's helpful to you if I hit colon and then space and now it says please enter a line number between and 184 well how to arrive at that number well this particular file that I'm have open right now has a hundred and eighty four lines in it therefore if I said line 100 notice how it takes me there right away I am hit enter I into anything else right there I'm on line 100 which is right right here okay if I were to hit escape it takes me back where I started if I were to hit enter so : 100 enter now I'm on that line okay and I was the cursor out of you can see right here but it's blinking right at the beginning of this line okay so that's a quick way of navigating around again I don't use it that much because I don't remember my line numbers well enough and really you shouldn't have these massive code files where you're looking for line 1500 okay you should be looking for hopefully you know a hundred or less is is your goal maybe a couple hundred to paint a circumstance okay but typically I don't find that one as useful but don't worry that's the least of this items power let's not filter it all I'm gonna type name and notice what it finds now first of all goes right to the first one automatically but it opens it in the preview window over here which means I haven't lost that place over here and it's not opening a whole bunch of tabs down T but it said okay first name yep I've sorry sorry name I found a first name is that helpful or maybe the first name over here in the per eye person model or how about the first name in person model or last name okay so it's finding a bunch of different names so I get to choose which one works for me it even listens to camel casing so if I were to say FN as oh you mean first name okay because F is the first letter of the first word and n is the first letter of the second word now since I named my variables well works okay so now what's done is instead of having to type this whole long thing I have type F in it finds my first names now it also find things like fast Nancy okay I'm not sure if it's a method name but it would find that as well because that also matches F and okay but this way we can search there very quickly and find things like business logic okay now notice it found assembly info so BL but also found business logic the file and it found business logic the class okay and since my found a and my class name of the same it found it twice so this allows us to filter down now if I say you know what guys want types I can click on this and it puts a t in there for me instead of me have a type T space and then my type so that's back to this question mark that's a type T a members and M F is file colon is line and pound is symbol so you can get use of this but I typically just search for everything I can very quickly if I say you know what that's I think it's in the helper method let's look for help Oh helper hit enter and taking right there which I'm Hardy there okay so if I say you know what it's probably in a model which model is it person model there we go I'm in person model very quickly navigate between your different files when you only have eight files in your entire project that's not a huge deal but when you have 80 or you know a couple hundred that's a really big deal especially if you use naming conventions because then if you remember convention then you can remember part of the file name and you can go right to it or at the very least you can limit that list so that you have only a couple on the list you can choose between them so ctrl T or ctrl comma it'll bring up this list just start typing okay and then if you don't want to go there he escaped if you do want to go there hit enter if you want to sort between them like move between them you just hit you're up and down keys to go into a specific one then you hit either enter or escape okay your mouth of course also works alright so that's number four number five is one you've already done a little bit of okay but this is refactoring so this is something that people often say oh I need a third party library or a do refactoring because you know these third party libraries offer me all these different things yes they do but there is a lot of power a lot of power built into Visual Studio so if you get controlled dot you Bram is a little quick action mentor or alt-enter as well so controlled are alt enter and brings up as little menu I've already used it for extracting interfaces and I do is a lot in my code control dot you'll hear a lot whenever I'm teaching well if you look on different items you may find there's nothing or you may find some fun stuff in it so for example this one move the declaration near where it's reference to the first time so notice that we have the declaration up here but I don't use person until down here so if I hit control dot I could move the declaration near where its first referenced that is a little bit of a memory savings we don't need to open up that memory slot until we need it and then since actually I don't use person again after this line the memory gets destroyed or can get destroyed is flagged for instruction right after the end of line 21 so that's a little bit memory savings okay so that's one refactoring but down here I have create a new class and I sometimes do this so I'm gonna we're gonna work on this this process data I go oh I'm going to need another class that does one thing and so I create a class right here so I can see it while I'm working on the code up here so I put it down here but this is not a good thing because I want this class to be in its own file called more logic so that way I can come over here and look for a file called more logic I don't have that right now is buried inside of the business logic so if I were just looking at this visually I'd have a hard time finding where more logic is I pry click on messy logic and go that's not it so keep looking where it's inside business logic that's not great Convention says that class gets its own file name the same as the class name well what I could do is I could right-click and say add class name it more logic and then open it up come back over to business logic copy this or actually cut it paste it in a new class and I'm done or I could control dot and I could say move type to more logic CS click it let's go on from here and notice now more logic gets over here done it's all taken care of for me all right it even cleaned up my using stance for me only has one using statement so that's kind of nice one click and you're done okay so control dot on a class name and say move it to its own CS file now notice up here there's a whole bunch of user famous and they're all grayed out and the reason why is we're not actually using any of these using students remember that using statements are just shortcuts so instead of saying system console dot write line we say console dot write line but then you have all this code up here that's not really used or useful well if I hit control dot and say remove unnecessary use it students they'll take care of all the ones I'm not using but check this out fix all occurrences in the document the project or the solution and watch this solution and it's okay here's all the place that gonna fix it okay so it's gonna look like now that's what that's gonna look like and so on so forth all the way down the list I hit apply now it's fixed here is no user Simmons we got more logit only one this model there's only one helper there's a few but they're all used okay business logic only has one so with that one selection I fixed my entire solution okay so if you don't like to have user statements up there that aren't being used that one little tweak fixes all that for you so that's just some of the things that control dot or alt-enter will do for you one of the things I recommend is that you go through and find all the different places that you might have some kind of refactoring you'll find a lot of them for example this one I did I have this new person he I'm sorry person model person equals new person and then I say person that first name equals and personnel last name equals well if I had controlled dots here it says you know what you can simplify that and it will change it from three lines of code where you have a declaration and then two assignments too which is really three lines of code but it's it's doing it at the Declaration point okay so I can hit I can say just fix it for this document okay we're gonna hit enter and it fixes it right there or I can fix it across again my entire solution and do that every time so just finding all the different things you could do is really helpful I mean you'll file lottery factors in refactorings in here that you didn't know existed and that you might use someday now some of them like I hit control dot here nothing comes up now Kate control that over here and these this there's text something comes up so I entered it to constant that's kind of cool click that and now I have a constant up here okay which I'm not sure what I do but but that's kind of neat but over here is nothing so just kind of kind of poke around try things out see if there's anything that might be useful try them and see what is useful to you okay so that's the control dot that's number five number six I have this class called messy logic does anything look wrong in here miss this is a mess okay you notice how all these curly braces are against the left side and really all the code is in fact we can make it even worse if I cut the whole thing hit shift tab now everything's in left hand side that's kind of ugly so what do I do to fix this well it used to be that you'd come through and you'd start hitting tab and then okay so let's tab twice I guess and then through it yeah don't do that hold a control key and then type II D problem solved okay so hold your control key and then hit bull e and then D before you let go your control it's also under edit advanced format document okay control IDI so what it does is it fixes your entire document and formats it in the right tabbing order which hopefully your tabs are actually smart tabs and there it's actually spaces behind scenes but that's another argument for node a so control IDI formats of document just in case you've got something out of whack now if it does not format the document for you that most likely means you have an error somewhere so just know that if this is what your document looks like and you are missing one of these and then hit ctrl e d it might not format now that one did so let's undo that control IDI fix it so there's certain times and I think maybe it's with if you leave off a semicolon or some of that it will not format it just look for the error or do a build build solution and find the error that way in the error list okay but control IDI formats your document for you number seven is a really interesting one when it's often overlooked so there's a tool called link pad whoo which the way is built it was built to be kind of like a quick editor for c-sharp where you try things out or build little bits of code to work well guess what there's something built into Visual Studio that does that as well so if we go to the View menu come down to other windows and come down to c-sharp interactive this is a fun window what this allows you to do is type little bits of c-sharp code and see if they work or how they work okay so for example I could say var time equals date time dot now and it says oops I need a my semicolon and it processes that line okay that lines been processed and run kind of a scripting language so now if I were to say time dot hour and says oh there's an error but if I if I say time dot hour without the semicolon yes okay the hours 23 so its 2300 hours or 11 p.m. at night so now I want to test out what this does an end how time dot power works so if I were trying to figure out how do I add three hours to a current time or maybe subtract three hours so I could say time Dodd's well how does it work I can try and you know figure it out who add hours so does add hours where I add a negative three work Nance is okay that's 8:23 p.m. well that's its 11:23 is therefore yes that works okay so that's I can try out your logic real quick one that I always get wrong is declaring a race I do it so so rarely that declaring a ray just doesn't stick in my brain for some reason so what I would do is come in here and say var just called I that's fine this is just for testing equals new int array and I think you do it like this we have curly braces and say 4 comma 3 comma 5 comma 9 and pie cynical at the end and hit enter and it seems to have worked now if I were to hits scroll one too many if RSA I rather want the second position which actually should be 5 and yes it is it's 5 so I've declared this correctly and I can access the correct one the correct way so now I know this little bit of code this declaration works I can actually copy this and paste it into my code so it's just kind of give you a really quick way of testing things out making sure you know how they work it's a simplistic thing it's not a full-featured visual studio so if you want to write you know methods and all the rest you should probably stick to using Visual Studio but for simple little thing to try and figure out or try out this is priceless ok so the way I get that again is view menu other windows c-sharp interactive alright number eight this one's a fun one so let's go to our our method in the data access we have load data so obviously this doesn't lead do anything it says load data it says get data from sequel which just writes a line to the console and so we're not really doing anything but let's pretend we are so we're passing a connection string and a sequel statement we're validating both of those returning faults if either of those has a length less than one but notice here we're running this get data from sequel before the validation and that's not right so what we need to do is cut this out I'm gonna come down here and put some spaces and put this in place or if my cursor is anywhere on this line I can hold down my Alt key and hit down arrow notice how it intelligently moves it around so now it's below I'll put space there by hitting the holding the Alt key and hit my down arrow I can move the line up and down just by using my arrow keys okay very quickly I can even highlight multiple rows and say nope that's not allowed to do so therefore hold the Alt key and hit down and notice they're now below it I have my Alt key and back up and they're now above it so very quickly you can move things around in your code without having to cut and move and paste and in all the rest just highlight the section you want you don't have to hide the whole thing so if I were to do something like this that still moves the whole line up and down okay so it's not a move partial it's a move the whole line okay so number nine this one's a little bit of a small one and yet it's something that people often miss so let's go a business logic and we have these two method calls down here load data and saved it and your mouse over it shows you some information but then it's really move it since goes away and it's kind of pain and maybe you you know you want to change this you're not sure what this is so it's completely gonna do first of all if you want to know what the parameters are put your cursor anywhere inside the parens for the parameters okay so anywhere inside here hit control shift space and that brings up your parameters notice highlights CNN see a little bit more bolt because that's what we're on right now if this is this right here is the CNN variable whereas this variable over here is the sequal variable notice how sequel is now a little more bolt so that brings up your parameter list it'll also show you if you have overloads so if I come up here to my console.writeline and hit control shift space it says okay you can put any one of these variables anything kind of move through okay up and down will give you different options so that's one way of doing things but then maybe you want to change this saved and said oops nope I didn't want to saved it here I want to load more data well I could just delete this and then type load and hope that's right or I can delete the whole thing back through the dot and then hit dot and that breaks up a whole list well that's inefficient instead when I cursor on saved yeah I hit ctrl J and brings up my intellisense I can even change to load it click it and now it says load it replaced saved it with low data I say it's small because there's not a lot to it and yet I use this almost every day almost every day I have to bring up a list and say oh what did I actually mean ok real quick ctrl J boom or what was that what was those parameters again ctrl shift space there we go there's my options for parameters okay so real quick it allows you to pull things up without having it do something like oh I'm gonna hit a comma here and now comes up and I hit back to kind of go away but now I'm fourteen nineteen so I gotta figure out nope just ctrl shift space or to bring up something besides console.writeline ctrl J all right number ten and this is a really fun one so what if I want to change all of these from public to internal now if you've watched my access modifiers video you know the difference between public and internal and say you know what I've been doing public and I really need to do internal instead well I could type out internal here that I had copied and pasted it over all five of these that's one option or what I can don't do is hit ctrl I'm sorry shift alt hold down shift and alt I'm like curse all the way shift alt and I hit my down key I hope you can see there there's a little blue cursor next to each of these if I were to start typing notice how I've typed in front of all five of those so if you even hit my delete key and then start changing all five lines now I can click off of it or hit escape and now all five lines are changed I could also hit I hold my Shift + Alt key together click and drag and highlight multiple lines using my mouse and now I can go back and type public as well same thing okay so you can change multiple lines as long as they're in alignment so I can't put a cursor here you know on the the start of int and a cursor on the start of my curly brace so there's some limitations there but you could very quickly create a list of something me if you have business logic and say you know what I'm gonna want to create a number of console right lines well shift alt you can say CW I'm sorry console dot write line testing one two three and there you go now I've written multiple console right lines and I usually change one two three to be something else for example you know something like that but now I've written those multiple lines that I having to write one line and copy and paste I can also modify all those lines if I say you know what nope I want to make these console right instead no problem I'm done alright so real quick multi cursor by holding down shift alt and then either doing it up and down arrows so shift alt down arrow and left and right would also highlight to the right or left or what you can do is hold down shift alt and then click and drag okay same thing so in this case I can delete all files that way and have them out of my code okay so that's that's all ten so the question I have for you now and we've gone through sweep seen a few extras main control dot is kind of like an optimization list unto itself that that thing is amazing for refactoring for moving things for updating things don't want they didn't show you what control dot well you go back and show you be like again it's really cool I change messy logic now it's better logic so if I said you know what no that's better logic the problem is that the class better logic doesn't match up with a messy logic filename no problem control dot rename file to better logic CS and there we go it's now better logic CS okay so control dot really powerful that's ten on its own at least but you know with all these different options a question I have for you is which ones didn't you know about and which ones do you think you're gonna use the most often okay so let me know in the comments down below give me a shout-out for the best one which number it is and why okay and if you you missed some of them you City I didn't even know what those let me know which ones you kinda hadn't seen before alright thanks for watching and as always I am Tim quarry [Music] you [Music]
Info
Channel: IAmTimCorey
Views: 79,462
Rating: 4.9630032 out of 5
Keywords: .net, C#, Visual Studio, code, programming, tutorial, course, training, how to, tim corey, C# training, C# tutorial, tim corey c#, top 10, visual studio tips and tricks, visual studio tips and tricks 2017, refactoring, refactoring c#
Id: xWcQhF-1hxA
Channel Id: undefined
Length: 40min 38sec (2438 seconds)
Published: Mon Aug 27 2018
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.