Join Gerry O'Brien for an in-depth discussion in this video Introducing Visual Studio, part of Learning C# (2014).
So once you've downloaded the version of Visual Studio that's going to be for the projects that you want to work on, it's important to get familiar with what we've referred to as the integrated development environment or the IDE. The ability to move around within the IDE makes your coding much more productive because of the various windows that are available within Visual Studio. If you're running on a Windows 8 computer, moving your mouse to the lower left corner, bringing up the Start screen, look for your specific Visual Studio icon.
Click it, and the application will start. When Visual Studio first starts, it brings up, by default, the Start Page. Now, when you get into customizations, you can choose not to display this when it starts up. Well, one of the things I always recommend to new students who are learning C#, VB, any of the .NET languages, and they're using Visual Studio, is leave the Start Page up. The reason being is because Microsoft provides different updates and bits and pieces of news and information about the .NET development, about C#, and Visual Studio, all on this page.
So the Start Page is a great way to find out, as you can see, about new announcements for what's coming up on Visual Studio. As well as what's new in Windows Desktop development, or links to places where you can learn how to start coding applications. So the Start screen is a great resource to have popping up on your screen when you first start. It's also very easy to get to creating new projects, opening existing ones or working on recent projects that you may have opened already. Let's go ahead and take a look at some of the other components of the Visual Studio window, like creating a new project and working in Visual C#.
So, we would select the Visual C# component in the left hand side for the language. Then in our Templates pane, we would choose the type of application that we want to create. In this case we'll just choose a Console Application quick and simple. You can provide a name for your application. We'll just leave the default for now. Visual Studio defaults to storing in your User Documents folder in a sub-folder called Visual Studio 2013 in Projects. Again, feel free to change this for whatever folder you decide you want to store your applications in.
Notice that Visual Studio also creates something called a Solution. And a Solution basically is a combination or a collection of projects, so you can have multiple projects within a solution. You can choose to create a directory for the solution, and it will use the solution name or the application name for that directory. And if you're on a system where you have Team Foundation Server, or some other source control, you can choose to add the files to the source control at the time. Let's go ahead and click OK, and what Visual Studio will do now is go through the process of creating a templated version of a project that allows us to create a Console Application.
So let's very quickly go through the Visual Studio window, get you a little bit comfortable with it so as we go through the remainder of the course, you'll understand some of the components that I work with. The Solution Explorer window here in the right hand side contains all of the information that is a part of our solution. Again, remember Visual Studio created a solution called ConsoleApplication1. That was based on the name that we provided. It gives you the name, an active configuration. We can talk about this a little bit later. You can provide a description for the solution if you choose, and a path to where you can find that solution file.
Notice it also has something called a Startup project. In this case, it's ConsoleApplication1. A startup project means, which project will run first when you click on the Start Debug menu. You can have multiple projects in your application that all fit under the single solution. In this case, we only have one project called ConsoleApplication1. The other components are here are Properties, and this deals specifically with the properties of the application itself. We can right click and open to open up the Properties window.
We're not going to cover all of these because a lot of them are project-specific. Here we're just focusing on the C# language so, you can leave all of these set at their default, but note that the properties are available for you to customize. References, these are essentially the different libraries that we'll use within the application itself. We may or may not use all of them, but Visual Studio defaults to building in some references to certain class libraries and certain name spaces within the .NET framework that they assume we would want to use in this type of an application.
We'll see examples of some of these. And a little bit later in the course we'll focus on the Base Class Library which talks a lot about some of these name spaces and classes. We also have an App.config file, which basically provides some configuration information for our application. Double clicking, it will open up a Code Editor window and you can see that it's simply an XML formatted file that provides very specific information. Start up, it basically knows that our run time will be version 4.0, and our supported .NET framework version is 4.5.
Very seldom will you ever change anything in the app.config for your simple applications. And then finally, the core of what we'll work with is our C# files. Program.cs is the default file that gets created by Visual Studio, specifically in this case for our Console Application. Program.cs is what's now open in our code window here on the left hand side. We can expand Program.cs, and drill down further into the different aspects in components of the actual application of the program pieces itself.
You'll notice that Program under Program.cs, represents the class that is indicated here. And Main, the string and the void represents our method that we actually see within our program class here. So, again, as we talked about in the introduction to C#, where we said that C# is an object-oriented programming language, everything that we create in C# is an object. It's created from a class. Even the Class program which is the entry-point for our application, is a class within the .NET language.
Now, C# also makes the use of various using directives or using statements at the top of our code file. So using System and using System.Collections.Generic are examples of using name spaces. We'll talk about name spaces in the course as well. And essentially, what we're doing here is making our code typing a little bit less arduous because we are bringing in the using name spaces which makes it easier for us to type our code later. We don't have to type System.Threading.Tasks.Class name, or what have you later on in the code.
So again, as we've been focusing on our Code Editor window, here you can see all of our code that we'll be typing in here. This is where we go through the process of entering the code that we want for our application. Note that Visual Studio provides us with some nice color coding, so all of our keywords will have specific colors assigned to them. Class names will typically be in this teal color. All of our keywords are typically in this blue colored. And then you'll see examples of some of the other IntelliSense and different features of Visual Studio as we start typing code later.
You get used to working with properties for various aspects over here in the Properties window. Again as you saw, if we clicked on Properties, it drops down specific information about a Properties folder, and or about the project that we're working with here. And, if you start building graphical applications with buttons and text boxes and things like that, on the form, properties for those items will display here as well. Before we end this session, let's take a little look at the toolbar. And you can see that we have the standard menus that you're familiar with in all Windows applications.
We also have a toolbar that provides some of the most commonly used buttons and commands that we'll be using as we work through our application. For example, we have a Start button here, and we can simply choose the Start button and our application will be compiled. You'll see that it was compiled down here in the Output window. You'll notice that we get specific pieces of information in this Output window that tells us what took place. And in this case if we scrolled all the way up we would see everything that happened during the build process.
If any issues or errors were generated we would see those in here. So all of the information for the build process here, we'll notice that this one specifically say that the thread has executed in the application is executed. You may have noticed that our application popped up very quickly and disappeared as well equally quickly. Because we chose debugging, there wasn't anything stopping the application, basically when we were finished with it. We’ll see as we start getting into C# and writing different pieces of application code, that these buttons will change based on what it is that we’re doing and what we have available in the window.
As an example, when we start debugging you’ll see some different buttons show up for the debugging process up here. So as you can see Visual Studio provides some great productivity tools. From the Solution Explorer to keeping track of your project files and folder structure, to the properties of the different aspects that you work with in your solution and the different components, to the Code Editor window with its color-coding and the IntelliSense features that we'll see a little bit later. Visual Studio is a tool, that I highly recommend you use, for creating your C# applications.
- Installing C#
- Working with loops
- Controlling program flow
- Using variables
- Building functions
- Creating and instantiating classes
- Catching errors
- Managing resources with the garbage collector
- Building collections